Moving Entity Framework EDMX classes to a separate DLL data layer

I started working and learning about the Entity Framework. Previously, when I was working with data access, I always tried to store it in a separate DLL, trying to separate my problems and not bring the data model classes to the presentation level.

Now when I create the EDMX file, it goes to the main project when I moved them and the code associated with it to the data DLL, while it compiled when I ran the solution, the error was caused in the Entities constructor, or rather, it base constructor in the ObjectContext class.

Is it possible to achieve this complete separation?

I saw this question that seems related , but after reading the comments, it seems that there is only a partial separation.

Edit This is the error I was getting:

Unable to load the specified metadata resource. 

I found this answer , so I will see if this solves my problem.

+4
source share
1 answer

Just re create the edmx file in a different assembly, not copy it. Just be aware that any assembly / program that uses this assembly must have an application file or web config containing a database connection string that has the same name as your edmx app configuration file.

It is not uncommon to store EF files for data access in a separate assembly or behind web services. Although the question of whether to allow POCO (models) to be exposed directly or not is preferable.

+5
source

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


All Articles