EF 4.1 EntityType has no key - composite

风格不统一 提交于 2019-12-03 12:57:20

I've solved the issue. I've just added additional key columns:

public class AlbumUser
{
    public Album Album
    {
        get;
        set;
    }

    public IdentityUser User
    {
        get;
        set;
    }

    [Key]
    [Column(Order = 0)]
    [StringLength(128)]
    public string UserId
    {
        get;
        set;
    }

    [Key]
    [Column(Order = 1)]
    public int AlbumId
    {
        get;
        set;
    }
}

Works with Entity Framework 6.1.3. I also added a basic Application class, but used the UserApplication as is (except for DatabaseGeneratedOption. This SQL was generated:

CREATE TABLE [dbo].[UserApplication] (
    [UserId] [int] NOT NULL,
    [ApplicationId] [int] NOT NULL,
    [SubscribedDate] [datetime] NOT NULL,
    CONSTRAINT [PK_dbo.UserApplication] PRIMARY KEY ([UserId], [ApplicationId])
)


CREATE TABLE [dbo].[Application] (
    [ApplicationId] [int] NOT NULL IDENTITY,
    [Name] [nvarchar](max),
    CONSTRAINT [PK_dbo.Application] PRIMARY KEY ([ApplicationId])
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!