0
我有这两种型号:流利的API,定义主键为外键
//Primary AND Foreign key 1
public int UserID {get; set;}
//Primary AND Foreign key 2
public int ProductID {get; set;}
我不知道如何设置这个两列作为主键和外键在同一时间! 你能帮我吗?
我有这两种型号:流利的API,定义主键为外键
//Primary AND Foreign key 1
public int UserID {get; set;}
//Primary AND Foreign key 2
public int ProductID {get; set;}
我不知道如何设置这个两列作为主键和外键在同一时间! 你能帮我吗?
也许你正在寻找这个
//Primary AND Foreign key 1
[Key]
public int UserID {get; set;}
[ForeignKey("UserID")]
public virtual IEnumerable<UserProfile> users;
//Primary AND Foreign key 2
public int ProductID {get; set;}
[ForeignKey("ProductID")]
public virtual IEnumerable<Product> products;
这将允许你从用户到产品的定位。
如果这不是你在找什么,请提供你所需要的
外键的表/实体的更多细节? – 2013-03-26 11:25:03
这是一个多对多的关系吗?看到这篇博文,它可能会帮助你:http://weblogs.asp.net/manavi/archive/2011/05/17/associations-in-ef-4-1-code-first-part-6-many-重视-associations.aspx – 2013-03-26 11:34:09