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
A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data.
To update this entity we need to attach the Department to the context and inform it to mark its status as Modified . Now if we call the SaveChanges method, the context will send an update query to the database.
Reference navigation property: A navigation property that holds a reference to a single related entity. Inverse navigation property: When discussing a particular navigation property, this term refers to the navigation property on the other end of the relationship.
Updating the Model If you need to re-scaffold the model after database schema changes have been made, you can do so by specifying the -f or --force option e.g.: dotnet ef dbcontext scaffold "Server=. \;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft. EntityFrameworkCore.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With