0

I have Entity Framework Repository Dal (EFRepositoryDAL.cs) And I wrote this code for Update Records.

        public void UpdateItem(T item)
    {
        using (WindowsaDairContext ent = new WindowsaDairContext())
        {
            ent.Set<T>().Attach(item);
            ent.Entry<T>(item).State = System.Data.EntityState.Modified;
            ent.SaveChanges();
        }
    }

And I have a model class like this.

public int UserDetailID { get; set; }
    public Nullable<int> UserId { get; set; }
    public bool Sex { get; set; }
    public Nullable<byte> CityID { get; set; }
    public Nullable<byte> EducationStatusID { get; set; }
    public Nullable<DateTime> Birthday { get; set; }
    public string UserIP { get; set; }
    public Nullable<bool> Online { get; set; }
    public string About { get; set; }
    public string ProfilePicture { get; set; }
    public Nullable<byte> PrestigePoint { get; set; }

But I want to update not all of fields with this repository class. Like I want to update only, "About","Profile Picture" fields. I want, the other fields can not change. But the other fields set NULL value. How can I solve this problem? Thanks.

rvighne
  • 19,255
  • 10
  • 49
  • 70
Güray Yarar
  • 143
  • 2
  • 13
  • I always .Find(id) the entity, change only fields that apply, then savechanges but this question may be more relevant http://stackoverflow.com/questions/14627999/how-to-update-only-modified-values-entityframework-5-0 – PMC Mar 16 '14 at 20:09
  • Thank you so much, I solved my problem :) – Güray Yarar Mar 16 '14 at 20:49

0 Answers0