数据库优先EF dnx ef dbcontext scaffold命令失败

时间:2016-06-02 16:03:10

标签: c# entity-framework

使用dnx ef dbcontext scaffold命令后,收到以下错误:

Unable to identify the primary key for table 'dbo.Report'.
Unable to generate entity type for table 'dbo.Report'.

当前的SQL架构。

 CREATE TABLE [dbo].[Report](
        [ReportID] [int] IDENTITY(1000,1) NOT NULL,
        [ReportName] [varchar](50) NOT NULL,
        [StoredProcedureID] [int] NOT NULL,
        [FileRepositoryID] [int] NULL
    ) ON [PRIMARY]

任何人都可以告诉我可能做错了什么?

1 个答案:

答案 0 :(得分:3)

您的ReportID列未设置为主键。只需添加PRIMARY KEY约束就可以了。

CREATE TABLE [dbo].[Report](
    [ReportID] [int] PRIMARY KEY IDENTITY(1000,1) NOT NULL,
    [ReportName] [varchar](50) NOT NULL,
    [StoredProcedureID] [int] NOT NULL,
    [FileRepositoryID] [int] NULL
) ON [PRIMARY]
相关问题