This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
i'm having a problem in saving entity and this is the scenario this is the schema of Customer Entity Customer : { (one to many) Addresses [] , (one to many)Contacts : [] } i have Web API + OData V4 + JSON.Net in the server I receive JSON Customer and deserialize it successfully, i save new entity using this method
Result : Customer Saved without related lists (Contacts + Addresses) whats the solution for this ? I Update Existing Entity using this method
Result : Customer won't Update (when AttachMode = Attach), or i have an exception Saying [Collection was modified; enumeration operation may not execute] (when AttachMode = Import) ---> because Addresses List changed Please help Regards |
|
|
AttachMode.Import will only import the direct entity so you would need to traverse all the association collections and import each child entity to import the full graph. AttachMode.Attach will attach the full graph of entities but if your entities are being imported with EntityState.Default then calling SaveChanges() won't do anything. You could use reflection to manually force the value of EntityState to .New or .Modified as needed however to work around this.
|
|
|
Thanks jeremy that solves the problem Solution :
|
|