public class User
{
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
}
public class Building
{
[Key]
public int BuildingId { get; set; }
public string BuildingName { get; set; }
}
public class UserBuildings
{
//these are the foreign keys
public int UserId { get; set; }
public int BuildingId { get; set; }
public int BuildingQuantity { get; set; }
}
我一直在寻找带有两个伪造键的其他例子,但他们似乎没有回答我的问题。
在UserBuildings表中,UserId和BuildingId都需要使UserBuildings表中的记录唯一。 (不会有两个具有相同UserId和BuildingId的记录,尽管它们可能具有相同的其中一个)
答案 0 :(得分:0)
这应该这样做
public class UserResources
{
[Key, Column(Order=0)]
public int UserId { get; set; }
[Key, Column(Order=1)]
public int BuildingId { get; set; }
public string BuildingName { get; set; }
}