I know during the retrieve, I can use Include() to load related Entities (http://stackoverflow.com/questions/2632323/how-to-use-foreign-key-in-l2e-or-ef). but when I want to save or insert data, how to handle those reference Entities?
that is for .Net 4. I am currently in .Net 3.5 and cannot do that
5YrsLaterDBA
2010-04-13 21:19:58
+1
A:
You need to hang the object within its graph, and call save changes. ObjectContext takes care of the rest.
Customer customer = myObjectContext.Single(c => c.Name == "Bob");
//new up an Order instance that has never been in the database.
Order order = GetOrderForCar();
//Add order to the Orders ObjectSet of a Customer
// This connects order to our ObjectContext.
customer.Orders.Add(order);
myObjectContext.SaveChanges();
David B
2010-04-13 23:25:50
A:
this is what I am looking for: http://stackoverflow.com/questions/480872/entity-framework-setting-a-foreign-key-property
5YrsLaterDBA
2010-04-14 13:26:04