In order to have entities generated for my SQL Server database views I have to:
select top 0 * into dbo.ItemsView2 from dbo.ItemsViewalter table dbo.ItemsView2 add constraint PK_ItemsView2 primary key nonclustered (ItemId)Scaffold-DbContext ...drop table dbo.ItemsView2Duplicate of #1679
The main issue is PK for a view, which may not be defined. Hence we cannot scaffold entity type for it always. So on the cautious side, we don't process views.
Once #9290 gets implemented, then perhaps the scaffolding tool can generate ViewType rather than EntityType for views, which can easily be user-edited.
Till then the approach you mentioned is the way to get scaffolding to generate entity type for views.
@smitpatel I do not see the point, tables can have missing PKs as well.
Views are mainly used as read-only so why require PK at all?
I would make it simple: no PK -> entity is read-only. No special base classes for views please!
That is, unless you are afraid that such error-proneness will lower perceived product quality but making it unnecessarily complicated does not do serve well either.
When I follow the advice of the thread starter to use tables to force the scaffolding wizard to generate the entity classes, I found that choosing a name beginning with double underscores like "__Customer" for the "template table" leads to correctly labeled Entityname "Customer", all you have to change is the referenced table name, which in this case can be done by cutting all "__"
It's 2019. Is there still no way for SQL Server Views to be generated? If this is the case, it would be a major setback for our plans to start using ASP.NET Core
@Ljupco7 I am not sure what you are asking, but the functionality this issue was originally asking for is available in EF Core 3.0 preview 6: https://github.com/aspnet/EntityFrameworkCore/issues/1679.
Most helpful comment
@smitpatel I do not see the point, tables can have missing PKs as well.
Views are mainly used as read-only so why require PK at all?
I would make it simple: no PK -> entity is read-only. No special base classes for views please!
That is, unless you are afraid that such error-proneness will lower perceived product quality but making it unnecessarily complicated does not do serve well either.