model view controller - Insert data into multiple table in entity framework -


i have 2 tables below. using db first approch

public class team {     public long id { get; set; }     public string name { get; set; }     public string description { get; set; } }  public class employee {     public long id { get; set; }     public long teamid { get; set; } // foreign key reference fom team table     public string name { get; set; }     public long referedby { get; set; } // foreign key reference fom employee table } 

now have insert data both table once. example need insert data below.

enter image description here

before introducing referred column using below code insert.

        team team = new team();         team.name = "team1";         team.description = "some description";          employee e1 = new employee();         e1.name = "jon";         employee e2 = new employee();         e2.name = "harish";          team.employee.add(e1);         team.employee.add(e2);          dbentity db = new dbentity();         db.set<team>().add(team);         db.savechanges(); 

after introducing referred column how can insert these reference database.

public long teamid { get; set; } // foreign key reference fom team table

you need one-to-one relationship see post:

http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx

before introducing referred column using below code insert.

you need here self referencing entity:

ef self one-to-many relationship


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -