ASP.NET MVC4 with Entity Framework
I'm designing an ASP.NET with MVC4 web application for a multi-tenancy application with different databases for different customers.
I'm planning to use Entity Framework and as I'm new to it, I have the following questions with the assumption that I follow database first model.
Is the EDMX file still needs to be generated? In other words, is the entity model generated in EDMX sufficient or is it required to create another layer of entity models and map it to the database?
Where should the entity conceptual models reside in my application architecture? Can I have all my models (DB models, view models) in a separate project?
Multitenancy would be the same database with a parent "Customer" object or something similar, are you building a multi-instance app (not sure if it's relevant to your question but an important distinction based on how you're deploying the app)?
To answer your other question(s) as simply as possible:
Entity Framework has come a long way from the days of competing with NHibernate and EF getting that "vote of no confidence". 4.x changed the ballgame you end of with many choices, unfortunately a lot of articles reference 4.x and so while you are using MVC 4 , you most likely nuget down the 5.0 version, and some of the examples are not so fun to get up and running.
Julie Lerman wrote a lot of the books on EF, Dbcontex, EF Code First.
You can skip creating an EDMX file, pros and cons to doing this. If you are the hard core coder you wants to develop POCO classes and then wire this up to talk to your database that is fine. OR , you can use the EDMX. There are variations of which you can use Model first, Migrations etc...
Code First is for both flexibility of whether you have an existing database or do not have a database.
I personally like to have many projects what to me replaced the "DAL" is a ProjectName.Data project look into the repository pattern ( and eventually the unit of work pattern).
You don't want to have business logic and code bleeding into your controllers. SRP (single responsibility principle) Keep your controller skinny. Nerddinner and a few other MVC projects on the internet try to make for a decent structure. MusicStore http://mvcmusicstore.codeplex.com/ and Contoso http://contosontiermvc.codeplex.com/ although they have a mvc3 main structure you will get a good insight as to how to structure your data.
You can generate from database by trying to create the Entity Framework from an existing database. (I think you right-click on the surface of a new model and Generate from Database)
They can reside in a different project, yes
上一篇: 如何在超过2张图片中找到相似度
下一篇: 带有实体框架的ASP.NET MVC4