Search code examples
entity-frameworkentity-framework-4sql-updatescalar-context

How to update navigation properties / related tables in EF?


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


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