我刚刚使用NuGet升级到最新的EF 4.1代码,现在我收到有关映射的错误.
我有这门课
public class UserApplication
{
[Key, Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int UserId { get; set; }
[Key, Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ApplicationId { get; set; }
[ForeignKey("ApplicationId")]
public virtual Application Application { get; set; }
public DateTime SubscribedDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
System.Data.Edm.EdmEntityType: : EntityType 'UserApplication' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet 'UserApplications' is based on type 'UserApplication' that has no keys defined.
Run Code Online (Sandbox Code Playgroud)
但是,我可以使用像这样的Fluent API
modelBuilder.Entity<UserApplication>().HasKey(obj …Run Code Online (Sandbox Code Playgroud) {"无法确定类型'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中使用多个主键?