没有主键的表的Scaffold-DbContext创建模型 [英] Scaffold-DbContext creating model for table without a primary key

查看:207
本文介绍了没有主键的表的Scaffold-DbContext创建模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为ASP.NET核心MVC应用程序中的特定表创建DBcontext和相应的模型.该表没有任何主键.

I am trying to create DBcontext and corresponding model for a particular table in ASP.NET core MVC application. This table doesn't have any primary key.

我正在运行Scaffold-DbContext命令-

I am running following Scaffold-DbContext command-

Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLE_NAME -force -verbose

在Package Manager控制台中,我可以看到此详细输出-

In Package Manager Console, I can see this verbose output-

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

我的环境是-VS2015 update3,.NET core 1.0.0,ASP.NET MVC核心应用程序.

My Environment is - VS2015 update3, .NET core 1.0.0, ASP.NET MVC core application.

反正有没有为没有主键的表创建模型吗?

Is there anyway to create a model for a table without primary key?

推荐答案

积压的支持EF Core中的复杂类型(那些没有实体密钥的类型):

Support for complex types (those that don't have an entity key) in EF Core is on the backlog: https://github.com/aspnet/EntityFramework/issues/246. That's why any attempt to reverse engineer a table without a primary key defined won't work at the moment.

这篇关于没有主键的表的Scaffold-DbContext创建模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆