Linq-To-SQL and WCF

WCF works on the objects like disconnected records. The object that is passed to the client is not the same as the one the is about to update. Therefore Linq does not know about the changes made to the record. As a result Linq will not do anything when calling the SubmitChanges.

To sort out this problem we need attach the instance record again to the list in the context:

context.GetTable().Attach(instance, true);

just before we call the SubmitChanges. But this is not always possible. I got the following error when calling this:

An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

The simple way of sorting this out was giving the ID field of the record the attribute of


This way Linq allows me to attach the existing instance and generate an UPDATE sql-statement.

See Also:

Author: Pouya Panahy

Microsoft certified DevOps engineer with passion in analysing, designing and implementing solutions for Azure Cloud with hands-on experience in security and quality assurence.

Leave a Reply