public class Table1
{
[Key]
int ID{get; set;}
Table2 table2{get; set;}
}
public class Table2
{
[Key]
int ID{get; set;}
int table1ID{get; set;}
//no instance of table i.e is relationship is uni-directional only
}
如何设置table1与table2的关系与Table1.ID和Table2.table1ID ???
答案 0 :(得分:0)
以此为例:
public class Table1
{
[Key]
int ID{get; set;}
Table2 table2{get; set;}
}
public class Table2
{
[Key]
int ID{get; set;}
int table1ID{get; set;}
[ForeignKey("table1ID")]
Table1 table1{get; set;}
//no instance of table i.e is relationship is uni-directional only
}
这意味着Table2
有一个Table1
引用(table1
),它的外键由ForeignKeyAttribute
指定为“table1ID”。