Entity Framework - mixing first models and databases?

For my first project using the Entity Framework, I decided to use the "first model" approach, in which I design my entities from which a script will be created to generate the necessary database tables. This worked quite well until I came across a situation where I could not get all the data elements that I needed in a single query (my LINQ skills are still limited).

Since I can easily write the query that I need in SQL, I was wondering if it is possible to write a view for my database and then generate an entity in my model in my model, in other words, mix two models / databases. Any ideas on this?

+3
source share
2 answers

You cannot mix models first and db-first. After you manually modify the database, you will no longer be able to use database generation from EDMX or delete your changes made directly to the database.

In some cases, this can be avoided by downloading the Entity Designer Database Generation Power Pack extension in Visual Studio 2010. When using this extension with VS 2010 Premium or Ultimate, you can use additional DB generation workflows and T4 templates that VS tools can use to comparing a newly created database with an existing database and creating only ALTER scripts.

, , , SSDL ( ). - Views, , , .

, SQL-, ExecuteStoreQuery ( EF4) .

+1

SqlQuery()?

ctx.Listings.SqlQuery("SQL Query Here", p1, p2...)
+1

Source: https://habr.com/ru/post/1795353/


All Articles