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;}
//no instance of table i.e is relationship is uni-directional only
}


如何使用 Table1.ID 和 Table2.table1ID 设置 table1 与 table2 的关系?

4

1 回答 1

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”来指定的。

于 2012-05-09T10:40:07.963 回答