Pra*_*vin 8 c# entity-framework asp.net-mvc-5
{"无法确定类型'Conference_Project.Models.Login'的复合主键排序.使用ColumnAttribute(请参阅 http://go.microsoft.com/fwlink/?LinkId=386388)或HasKey方法(请参阅http:/ /go.microsoft.com/fwlink/?LinkId=386387)指定复合主键的顺序."}
[Table("ConferenceLogin")]
public class Login
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long confid { get; set; }
[Key]
public string emailID { get; set; }
[Key]
public string registration { get; set; }
[Key]
public long regNo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Version Used : EntityFramework.6.1.3 And MVC5
Run Code Online (Sandbox Code Playgroud)
我希望这个独特的价值(emailID,registration,regNo该组则所有的主键的EntityFramework显示错误)
如何在EntityFramework中使用多个主键?
小智 7
虽然我不确定为什么会出现这个错误的基础逻辑,但我确实对我正在上课的项目有同样的问题.对我有用的是在Key标签转向中添加一个Column(order)装饰器
[Key]
Run Code Online (Sandbox Code Playgroud)
成
[Key, Column(Order = n)]
Run Code Online (Sandbox Code Playgroud)
其中n是所讨论密钥的从0开始的索引.
有鉴于此,您的课程应如下所示:
[Table("ConferenceLogin")]
public class Login
{
[Key, Column(Order = 0), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long confid { get; set; }
[Key, Column(Order = 1)]
public string emailID { get; set; }
[Key, Column(Order = 2)]
public string registration { get; set; }
[Key, Column(Order = 3)]
public long regNo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
希望这对你有用,对我来说也是如此!
| 归档时间: |
|
| 查看次数: |
7314 次 |
| 最近记录: |