以下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