How to update(attach) an entity with children?
Posted: Mon 09 Jan 2012 18:15
Hi
I am trying to figure out if LinqConeect offers an alternate to modify an entity.
In linq to sql, when doing this with a disconnected entity
will give me "Cannot add an entity with a key that is already in use."
if doing this
will give me "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."
To resolve it, the simplest way was to remove all UpdateCheck or do copy of properties from the modified entity to the in-context entity
However, I still need the concurrency check and I also don't want to do a manual copy because the entity has multiple children.
Another popular way in linq to sql is to detach the entity first, and then attach it back. Well, it has been 4 or 5 years, is there any better neat way now?
Also wondering if linqConnect offers a better alternate to achieve an update like this?
thanks
I am trying to figure out if LinqConeect offers an alternate to modify an entity.
In linq to sql, when doing this with a disconnected entity
Code: Select all
context.Attach( entity, original )
will give me "Cannot add an entity with a key that is already in use."
if doing this
Code: Select all
context.Attach (entity, true )
To resolve it, the simplest way was to remove all UpdateCheck or do copy of properties from the modified entity to the in-context entity
However, I still need the concurrency check and I also don't want to do a manual copy because the entity has multiple children.
Another popular way in linq to sql is to detach the entity first, and then attach it back. Well, it has been 4 or 5 years, is there any better neat way now?
Also wondering if linqConnect offers a better alternate to achieve an update like this?
thanks