我有一个简单的控制台应用程序,我正在尝试搭建我所有的模型,但我有一些模型没有定义主键,实体框架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在没有定义主键的情况下,我是否缺少任何参数或帮助来搭建模型?
发布于 2018-06-15 10:31:12
这是意料之中的行为。EF核心必须在表上需要一个PrimaryKey,否则它将不会搭建该表。因此,要从这样的表生成模型类,您应该将PK添加到表中。
发布于 2019-07-05 16:15:12
这在EF core 3.0之前是不可能的,你可以在Ef core 3.0上测试它,Ef core 3.0目前正在预览中。
https://stackoverflow.com/questions/50865848
复制相似问题