Question

I have an object Customer with a navigation property Days (days is a separate table which have - day_id, customer_id - FK).

mycontext.Customers.ApplyCurrentValues(cust);
mycontext.SaveChanges();

This only updated the scalar properties of Customer, not days. Is There any smart way to update Days? (without iterating manually on days..)? if not - is there any best practice to update the second table (days)? If it's possible please write the explicit code should be used.

p.s. I'm currently using EF 4.0

Était-ce utile?

La solution

No you can't do it without iterating manually on related entities. Have a look at this question and answer which might be helpful.MVC Entity Framework modifying child entities

Autres conseils

You can use GraphDiff library if you want a simple and easy way to work with disconnected object.

mycontext.UpdateGraph(cust, map => map.OwnedCollection(x => x.Days));
mycontext.SaveChanges();

This will insert or update customer object and also updating Days collection as well.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top