我有一个简单的控制台应用程序,我正在尝试构建所有模型,但其中一些模型没有定义主键, 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/