gpt4 book ai didi

sql-server - Entity Framework 6 数据库首先不会在具有复合键的表上生成实体

转载 作者:行者123 更新时间:2023-12-04 02:01:46 25 4
gpt4 key购买 nike

假设我有以下带有复合主键的表定义:

create table [dbo].[CustomerRequests] (
[CustomerId] int not null,
[RequestId] int not null,
constraint [PK_CustomerRequests] primary key clustered ([CustomerId] asc, [RequestId] asc),
constraint [FK_CustomerRequests_Customers] foreign key ([CustomerId]) references [dbo].[Customers] ([CustomerId]),
constraint [FK_CustomerRequests_Requests] foreign key ([RequestId]) references [dbo].[Requests] ([RequestId])
);

当我更新模型以包含此表时, Entity Framework 无法生成实体类。这是由于复合主键吗?有没有办法让Entity Framework生成实体类?

最佳答案

Gert Arnold 的评论为我指明了正确的方向,this answer 也是如此。 .

一旦我在两个主键之外添加了另一列, Entity Framework 就生成了实体。以下是 EF Database First 将为其创建实体的示例表定义:

create table [dbo].[CustomerRequests] (
[CustomerId] int not null,
[RequestId] int not null,
[TimestampUtc] datetime not null,
constraint [PK_CustomerRequests] primary key clustered ([CustomerId] asc, [RequestId] asc),
constraint [FK_CustomerRequests_Customers] foreign key ([CustomerId]) references [dbo].[Customers] ([CustomerId]),
constraint [FK_CustomerRequests_Requests] foreign key ([RequestId]) references [dbo].[Requests] ([RequestId])
);

关于sql-server - Entity Framework 6 数据库首先不会在具有复合键的表上生成实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46736183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com