相关疑难解决方法(0)

EF 4.1 EntityType没有键 - 复合

我刚刚使用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)

composite-key entity-framework-4.1

8
推荐指数
1
解决办法
1702
查看次数

无法确定类型的复合主键排序

{"无法确定类型'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中使用多个主键?

c# entity-framework asp.net-mvc-5

8
推荐指数
1
解决办法
7314
查看次数