0
我會用一個例子解釋:儘管影響相同的值,實體框架實體處於修改狀態(並推送更新)?
//get an entity
var myEntity context.GetClient(543622);
// imagine this client has already a property myValue=10
// (retrieved from the database)
//set again this value
myEntity.myValue = 10;
// then we get the modified for this entity
ObjectStateEntry ose = null;
_context.ObjectStateManager.TryGetObjectStateEntry(myEntity.EntityKey, out ose);
// the ose.EntityState is modified
// and here count = 1 ??!!...
var count = ose.GetModifiedProperties().Count();
//at last a SaveChanges push a commit to the bdd
// (tracked with SQL Server Profiler).
_context.SaveChanges();
看來,不管你同一個值設置爲一個實體preperty,狀態更改爲修改和更新推到DB。我很驚訝一個這樣的行爲......
新芬」
你的問題是什麼?你問我們如何不驚訝? – 2010-12-23 16:27:22