Detect changes in ObjectSet in Entity Framework 4.0?

I want to check if there are any changes to the table in EF 4.0 with the following code:

var a = context.Users.GetHashCode();

AddNewUser();

context.SaveChanges();

var b = context.Users.GetHashCode();

a == b, I don’t know why?

Any help would be appreciated!

+3
source share
2 answers

GetHashCodehas an absolute different use . You cannot detect changes in ObjectSet, because it is the entry point to the corresponding database table (s). You can detect the changes prepared in ObjectContext, but only before the changes SaveChangesare accepted (the changes are also accepted by default ). To get changes from ObjectContext, use:

context.ObjectStateManager.GetObjectStateEntries(...)
+4
source

, GetHashCode ObjectSet, ?

0

Source: https://habr.com/ru/post/1794108/


All Articles