EF Core 2.1 has new feature - Query Types.
Some of the main usage scenarios for query types are:
- Serving as the return type for ad hoc FromSql() queries.
- Mapping to database views.
- Mapping to tables that do not have a primary key defined.
- Mapping to queries defined in the model.
I upgrade project to Core 2.1, but Scaffold-DbContext still does not generate database views. I have to use a special parameter or the Scaffold-DbContext does not support it?
Here's a hackish but working solution:
Key
attribute on a column and then remove after scaffolding is completed.DbSet<T>
should have gotten added where T
is the class created in step#2. Change DbSet
to DbQuery
.In OnModelCreating
method of DbContext
, add following code:
modelBuilder.Query<POCO from step#2>().ToView("Name of the view");
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With