简体   繁体   中英

Detect changes in ObjectSet in Entity Framework 4.0?

I want to check if there is anything changes in a 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 helps would be appreciated!

GetHashCode has absolutelly different usage . You can't detect changes in ObjectSet because it is entry point to related database table(s). You can detect changes prepared in ObjectContext but only before you accept changes (default SaveChanges also accept changes). To get changes from ObjectContext use:

context.ObjectStateManager.GetObjectStateEntries(...)

有可能GetHashCode没有考虑ObjectSet项目的真实内容,你不能简单地检查你的情况下的计数或检查更改的属性?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM