entity-framework-core - Entity Framework 核心 2.1 上的脚手架无键模型

标签 entity-framework-core entity-framework-core-2.1

我有一个简单的控制台应用程序,我正在尝试构建所有模型,但其中一些模型没有定义主键, Entity Framework 2.1 支持此类表,但仍然收到此警告

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

所以它不会生成模型

 dotnet ef dbcontext scaffold "Server=MyServer;Database=MyDb;Trusted_Connection=True;MultipleActiveResultSets=true" Microsoft.EntityFrameworkCore.SqlServer -o Models -f

我是否缺少任何参数或对未定义主键的支架模型的任何帮助?

最佳答案

这是预期的行为。 EF Core 必须需要表上的主键,否则它不会对该表进行脚手架。因此,要从此类表生成模型类,您应该将 PK 添加到表中。

关于entity-framework-core - Entity Framework 核心 2.1 上的脚手架无键模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50865848/

相关文章:

c# - 字符串参数 'migrationId' 不能为空

mysql - Ef core 在查询过滤器或 TPH 中创建子查询而不是联接

c# - 如何在 SaveContext 上更新修改和删除的实体?

c# - 寻找一种有效的方法来使用 Entity Framework Core 为每一行检索一组多对多子项

Xamarin 表单和 Entity Framework 核心 NetStandard

c# - Entity Framework 核心: many-to-many relationship with the same object

c# - 一个实体上的多个属性需要多对多关系 EF Core 2.2

c# - 影子主键

asp.net - EF Core 2.1项目Add-Migration NullReferenceException

c# - 对 ITVF 的引用引发 "second operation started on this context before a previous operation completed"异常