Scaffold-DbContext creating model for table without a primary key

半腔热情 提交于 2019-12-05 10:04:24

问题


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.

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

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'.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/39701068/scaffold-dbcontext-creating-model-for-table-without-a-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!