asp.net - attaching an entity with a related entity to a new entity framework context -
When I want to update the unit, then to attach a unit to an entity in a new context, I have been trying to bring the head.
I have a person table (generalized for personnel), which has a language-bound field, this field is the second table through EF through EF, Along with the primary key (1-M) as the language. I need to update the language preference of a particular person, however, this relation is associated with the old context, as I think the references to a "object should not be referenced on the given line with many examples of event change tracker. Could "error. What is the way to engage the language unit in the new context in relation to the Personnel (Person) unit ???
The institutions use the one which is not separated into the original gupperson () method. To return the preferred language, add the () method
Navigation on the preferred language person table is the name of the property ...
Public Static Zero Update User (Personnel Original User, Personnel NewUser) {(The Admin Model TheModel = New Administrator Model ()) {(IEntityWithChangeTracker) Original User) SetChangeTracker (empty); ((IEntityWithChangeTracker) originalUser.PreferredLanguage) .SetChangeTracker (zero); TheModel.Attach (original user); - Error line TheModel.ApplyPropertyChanges ("person", new user); TheModel.SaveChanges (); }}
Thanks Sean
Avoid these types of problems You should query GetPersonnel ()
a NoTracking
.
Ie
ctx.Person.MergeOption = MergeOption. Not Tracking; // and then query according to normal.
In this way, you can get a graph of connected entities (say that you use . () () Is not included which is not attached. Note that if you try to isolate entities manually, then this will not work, because by doing so you can read your graph.
Hope it helps
Alex
Comments
Post a Comment