Asp.net 如何首先在EF代码中将主键映射到非主键?

Asp.net 如何首先在EF代码中将主键映射到非主键?,asp.net,asp.net-mvc-3,entity-framework,linq-to-entities,ef-code-first,Asp.net,Asp.net Mvc 3,Entity Framework,Linq To Entities,Ef Code First,我有两张桌子 如何设置table1与table2、table1.ID和table2.table1ID之间的关系???举个例子: 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{ge

我有两张桌子


如何设置table1与table2、table1.ID和table2.table1ID之间的关系???

举个例子:

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”。

这不是我所需要的@lymchaeti一定误解了。您想通过“table1ID”将这两个表关联起来,对吗?
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
}