Rami Alshareef
Rami Alshareef

Reputation: 7140

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?

Upvotes: 1

Views: 161

Answers (2)

Steven
Steven

Reputation: 172646

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);

Upvotes: 3

Andrey Stukalin
Andrey Stukalin

Reputation: 5939

I think you should check property

my_object.EntityState

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

Upvotes: -1

Related Questions