What is the best way to share a single Entity Framework 4 data model between multiple applications (designed to access the same database at the same time)?

The project ("decision" to say in terms of VS) of my consists of the ASP.Net 4 Dynamic Data Entities web application, some WinForms applications, some WPF applications, some services. All of them are designed to work with one SQL Server database generated from the Entity Framework 4 model in the form of a table for each type, with many inheritances and multiple binding relationships.

Where is the best place to place my model? In a separate class library, a copy in each project, in one project, etc. Which name should I use best? Is it a good idea to call it MySolution.MyClassLibrary.MySolutionEntities or just MySolutionEntities or just MySolution? Can you share any useful experiences on this?

+1
source share
1 answer

Put your model and any support classes (for example, additional entity functions in partial classes, repository and implementation interfaces, and validation) in a separate class library. This is by far the best way to share this functionality.

Compile this into your assembly and you can link to any number of projects - your ASP.NET web applications, your ASP.NET MVC applications, your WPF and Winforms applications, no matter what you do - just add a link to your model assembly EF.

As for naming, use something that makes sense. Do not attach it to a specific project or decision - give it a descriptive name. What is the model - what data is contained in it?

You could call it something like YourCompany.HumanResources.DataModel or something else - do not make it specific to a project, as you are likely to use it several times in different projects.

+4
source

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


All Articles