The essence of the problem is, as always, in performance, a lot of requests are made to the database by sample. Made a convenient presentation in the database itself, now the selection is done in one request.

The question is how to make a view when the database is initialized at the COdeFirst approach? If the first is impossible to do (as I did manually through MS SQL Management Studio), how can I access it in code (since CodeFirst, then the system sees only those tables that are represented by models)?

  • In the migration, you can execute any sql script, after creating the view in this way, it can be accessed like this: _context.Database.SqlQuery<КлассМодели>("select * from ВашаВью") - Bald
  • It is understandable, I can make any database request, but the question is how to get them, the entity is not defined for View. - Dennis Spade
  • SqlQuery allows you to get the result of the sql query in the form of a filled class instance, of course you will have to create a class for the materialization, but you don’t need to add it to DbContext - Bald
  • I have a base with IdentityFramework, there is no SqlQuery method there. - Dennis Spade
  • In your project, the context is inherited from IdentityDbContext which in turn is inherited from DbContext ? - Bald

1 answer 1

Problem solved in pre-release version of EF Core 2.1 - added view support