Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework core 实体框架核心2.1上的脚手架无键模型_Entity Framework Core_Entity Framework Core 2.1 - Fatal编程技术网

Entity framework core 实体框架核心2.1上的脚手架无键模型

Entity framework core 实体框架核心2.1上的脚手架无键模型,entity-framework-core,entity-framework-core-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=MySe

我有一个简单的控制台应用程序,我正在尝试构建我的所有模型,但我有一些模型没有定义主键,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必须在表上使用PrimaryKey,否则它将无法构建该表。因此,要从这样的表中生成模型类,您应该将PK添加到表中。

这在EF core 3.0之前是不可能的
您可以在Ef core 3.0上测试它,该版本目前正在预览中。

我知道它是一个链接,但您必须指定一些内容来帮助识别查询中的项目。我知道这是预期的行为,但在2.1版本中,他们支持没有主键的表不幸的是,我有一个现有的数据库,我无法更改任何表我安装了github.com/ErikEJ/EFCorePowerTools,但不幸的是,它也没有生成这些表,感谢SEF Core 3发布,我刚刚能够用它构建一个数据库(该数据库也有类似的问题),请记住升级相关包,如
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools