EF 6.02生成模型时出错

时间:2014-01-07 10:16:55

标签: sql-server entity-framework sql-server-2012 visual-studio-2013 entity-framework-6

以下SQL脚本适用于2个相关表。当我尝试生成EF模型(EF 6.02)时,出现以下错误:

错误13101:引用约束的从属角色中的所有属性的类型必须与主体角色中的相应属性类型相同。实体'协议'上的属性'from_party_id'与参照约束'AGREE_PR_FK'中实体'party_relationships'上的属性'to_role_type_code'的类型不匹配。

第一张表

CREATE TABLE [dbo].[party_relationships](
    [to_party_id] [numeric](8, 0) NOT NULL,
    [to_role_type_code] [varchar](10) NOT NULL,
    [from_party_id] [numeric](8, 0) NOT NULL,
    [from_role_type_code] [varchar](10) NOT NULL,
    [from_date] [datetime] NOT NULL,
    [priority_code] [varchar](10) NOT NULL,
    [status_code] [varchar](10) NOT NULL,
    [thru_date] [datetime] NULL,
    [pr_comment] [varchar](240) NULL,

 CONSTRAINT [PR_PK] PRIMARY KEY CLUSTERED 
 (
   [to_party_id] ASC,
   [from_party_id] ASC,
   [to_role_type_code] ASC,
   [from_role_type_code] ASC,
   [from_date] ASC

 ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
 ) ON [PRIMARY] 

第二张表

 CREATE TABLE [dbo].[agreements](

   [agreement_id] [numeric](8, 0) NOT NULL,
   [agreement_type_code] [varchar](10) NOT NULL,
   [to_party_id] [numeric](8, 0) NOT NULL,
   [from_party_id] [numeric](8, 0) NOT NULL,
   [pr_from_date] [datetime] NOT NULL,
   [from_role_type_code] [varchar](10) NOT NULL,
   [to_role_type_code] [varchar](10) NOT NULL,
   [agreement_date] [datetime] NOT NULL,
   [from_date] [datetime] NOT NULL,
   [thru_date] [datetime] NOT NULL,
   [description] [varchar](240) NOT NULL,

 CONSTRAINT [AGREE_PK] PRIMARY KEY CLUSTERED 
 (
  [agreement_id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
 ) ON

[主要]

'AGREE_PR_FK'约束定义如下:

ALTER TABLE [dbo].[agreements]  WITH CHECK ADD  CONSTRAINT [AGREE_PR_FK] FOREIGN KEY([to_party_id], [from_party_id], [to_role_type_code], [from_role_type_code], [pr_from_date])
REFERENCES [dbo].[party_relationships] ([to_party_id], [from_party_id], [to_role_type_code], [from_role_type_code], [from_date])

看起来EF正在尝试不按顺序游行相关列。或者有什么我想念的东西!

我在Windows 8.1上使用SQL Server 2012和VS 2013 Ultimate

1 个答案:

答案 0 :(得分:0)

这已在EF6.0.2工具中修复,因此您需要重新安装工具。您可以从here

获取包含修复程序的版本