Navigation properties can be used to add data in the Entity Framework.
When two tables have a primary foreign key relationship, and the data added to both tables is data that does not exist, you can use the navigation properties to insert the data. For example, the following two tables:
When you add new data to two tables, you can add two data to the datasheet by writing it this way.
private void Form1_Load (object sender, EventArgs e) { testentities te=new testentities (); Define a context instance customer customer = new Customer () //customer data { cusname = "Syq", subtime = " December 19, 2014 ", }; Order order = New Order () //order data { ordercontent = "PC", customer = Customer // Assigns the Customer entity object to the navigation property in the Order entity object }; Te. Order.add (order); Add data to the context te. SaveChanges (); }
The Entity Framework learning is just beginning and needs to be learned in the project.
Entity framework-using navigation properties to add data