开发者

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

开发者 https://www.devze.com 2023-01-29 10:01 出处:网络
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

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

精彩评论

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