A project (a "solution" to say in VS terms) of mine consists of an ASP.Net 4 Dynamic Data Entities web application, some WinForms applications, some WPF applications, some services. All they are intended to work with on开发者_如何学运维e SQL Server database, generated from an Entity Framework 4 model as table-per-type, with lots of inheritance and multiple self-referencing relations.
Where do I best put my model? In a separate class library, a copy in every project, in one project, etc. What naming should I best use? Is it good idea to name it MySolution.MyClassLibrary.MySolutionEntities, or just MySolutionEntities or just MySolution? Can you share any useful experience on this subject?
Put your model and any support classes (like additional entity functionality in partial classes, repository interfaces and implementations and validation) into a separate class library. That's by far the best way to share that functionality.
Compile that into its own assembly, and you can reference that from any number of projects - your ASP.NET web apps, your ASP.NET MVC apps, your WPF and Winforms apps, whatever it is you're doing - just add a reference to your EF model assembly.
As for naming - use something that makes sense. Don't "tie it" to a specific project or solution - give it a descriptive name. What is the model - what data is contained in it?
You could name it something like YourCompany.HumanResources.DataModel
or whatever - don't make it specific to a project, since you'll likely use it several times in various projects.
精彩评论