title: Don't save null image data if image was not re-uploaded Asp.net mvc
body: <p>I have been following the SportsStore example project in Apress Pro ASP.NET MVC 3 Framework book and trying to apply the concepts to my application. One area that is bugging me is that in the sample, I can add an image to a product and it gets saved to the database, but if I edit any given product, without uploading a new image for it, the image data is cleared out. I want to be able to edit a product, but if the image data returned from the HTTP post is null, that I want Entity Framework to keep the exisiting image data (and content type). How can I command EF to not update this image field with null if a new image isn't uploaded?</p>
  <pre><code>[HttpPost]
      public ActionResult Edit(int id, HttpPostedFileBase image1, FormCollection collection)
      {
          using (ISession session = Database.OpenSession())
  
          {
              try
              {
                  DoctorsModel db = new DoctorsModel();
                  db.Id_d = id;
                  db.D_city = collection[&quot;D_city&quot;].ToString();
                  db.D_egn = collection[&quot;D_egn&quot;].ToString();
                  db.D_email = collection[&quot;D_email&quot;].ToString();
                  db.D_family_name = collection[&quot;D_family_name&quot;].ToString();
                  db.D_first_name = collection[&quot;D_first_name&quot;].ToString();
                  db.D_gender = collection[&quot;D_gender&quot;].ToString();
                  db.D_mid_name = collection[&quot;D_mid_name&quot;].ToString();
                  db.D_phone = collection[&quot;D_phone&quot;].ToString();
                  db.D_specialty = collection[&quot;D_specialty&quot;].ToString();
                  db.D_room = collection[&quot;D_room&quot;].ToString();
                  db.D_floor = collection[&quot;D_floor&quot;].ToString();
  
                  if (image1 != null)
                  {
                      db.D_picture = new byte[image1.ContentLength];
                      image1.InputStream.Read(db.D_picture, 0, image1.ContentLength);
  
                  }
  
                  using (ITransaction transaction = session.BeginTransaction())
                  {
                      session.SaveOrUpdate(db);
                      transaction.Commit();
                  }
  
                  return RedirectToAction(&quot;Index&quot;);
              }
              catch
              {
                  return View();
              }
          }
      }
  </code></pre>
  <p>Model</p>
  <pre><code> public class DoctorsModel
  {
      public virtual int Id_d { get; set; }
      [Display (Name =&quot;Име: &quot;)]
      public virtual string D_first_name { get; set; }
      [Display(Name = &quot;Презиме: &quot;)]
      public virtual string D_mid_name { get; set; }
      [Display(Name = &quot;Фамилия: &quot;)]
      public virtual string D_family_name { get; set; }
      [Display(Name = &quot;Специалност: &quot;)]
      public virtual string D_specialty { get; set; }
      [Display(Name = &quot;Пол: &quot;)]
      public virtual string D_gender { get; set; }
      [Display(Name = &quot;Тел.номер: &quot;)]
      public virtual string D_phone { get; set; }
      [Display(Name = &quot;Email: &quot;)]
      public virtual string D_email { get; set; }
      [Display(Name = &quot;ЕГН: &quot;)]
      public virtual string D_egn { get; set; }
      [Display(Name = &quot;Град: &quot;)]
      public virtual string D_city { get; set; }
      [Display(Name = &quot;Снимка: &quot;)]
      public virtual byte[] D_picture { get; set; }
      [StringLength(5)]
      public virtual string D_rating { get; set; }
      public virtual string D_content { get; set; }
      [Display(Name = &quot;Стая:&quot; )]
      public virtual string D_room { get; set; }
      [Display(Name = &quot;Етаж: &quot;)]
      public virtual string D_floor { get; set; }
      
      
  }
  </code></pre>