开发者

LINQ2SQL: How to tell if an Entityobject has been updated/Modified before posting to database or not?

How to know if an object (pulled from some datacontext) got updated during some process or not?

is there any build-in method/prop can do this job, or I must define one (prop, e.g.: Updated) and set it to true every time object got modified?开发者_运维知识库


You can achieve this by querying the GetChangeSet property of the DataContext class. Here's an example:

object entity;

bool hasChanged = context.GetChangeSet().Updates.Contains(entity);


I think you should check property

my_object.EntityState

http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.entityobject.entitystate.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜