Let's say we have three tables:
Table1is the principal tableTable2andTable3are dependent tables. They have 0..1<--->1 relation withTable1Table1.idis an identity column, automatically generated by the databaseTable2,Table3do not have an identity column
This will allow me to insert in principal entity Table1 without dependent. I read that when you make StoreGeneratedPattern = identity. EF reads the value generated in the database and stores it in memory cache.
So I want to assign that Table1_id to Table2 which is a dependent table. So my questions are
How would I get that
id? I want to assign that id to table2table2 t2 = new Table2(){ id = ? }; // How?Now coming back, another question is: do I have to assign
virtualto null in controller?Table1 t1 = new Table1() { table2 = null, table3 = null } // ???
Table1
public partial class table1
{
public int Id { get; set; }
public string username { get; set; }
public virtual table2 table2 { get; set; }
public virtual table3 table3 { get; set; }
}
Another related question: I wanted Table1 to have either Table2 or Table3 related. So how would I connect them?