我想在实体框架数据模型中定义一个关系,即1到1,其中一端是一个表的主键,另一端是另一个表上的外键。例如:
table: aspnet_Users
w/ col: UserId guid Primary Key使用与User表的UserId列相关的aspnet_Users表的AspUserId属性:
table: User
w /col: UserId int Primary Key
w /col: AspUserId guid当我尝试这样做时,我会收到一个错误,因为AspUserId字段不是它的表中无法工作的主键:
错误21错误113:多重性在关系‘FK_User_aspnet_User’中的角色'User‘中无效。因为依赖角色属性不是关键属性,因此依赖角色的多重性的上限必须是*。
发布于 2010-12-20 03:16:26
作为对海报的回应,用户表:
CREATE TABLE [dbo].[User](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[AspUserId] [uniqueidentifier] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
[CreatedDate] [datetime] NOT NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[User] WITH CHECK ADD CONSTRAINT [FK_User_aspnet_Users] FOREIGN KEY([AspUserId])
REFERENCES [dbo].[aspnet_Users] ([UserId])
GO
ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_aspnet_Users]
GOhttps://stackoverflow.com/questions/4485350
复制相似问题