1

I'm trying to update my model in the POST of my controller:

I'm getting the original values from the database here:

var origAttributes = (from tAttr in db.TeacherAttrs where tAttr.ID == ta.ID select tAttr);

I have a property in the my ViewModel that is a type of db.TeacherAttr

property name: ta.DMTeacherAttr

I'm wondering is there a way to compare the values between what my model (ta.DMTeacherAttr) has and what is in the database already?

I am using Entity Framework 5 as well.

2 Answers 2

1

Have you tried this:

var origTeacherAttr = db.TeacherAttrs.Find(ta.ID);

if(origTeacherAttr.DMTeacherAttr==ta.DMTeacherAttr)
{
//Do something
}
Sign up to request clarification or add additional context in comments.

Comments

0

If the purpose of comparing is to see what fields exactly needed to be updated then Entity Framework will do it for you, and you need to do two things :

  1. Map your ViewModel to your Model
  2. Set all your Model properties to virtual

Entity Framework will wrap your classes with a proxy and will track their properties .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.