MVC, Entitiy Framework and Repository

Hi experts

I'm building my first MVC app, now I have some questions about how to separate the different parts of the app.

So far I have three projects
1. the mvc app
2. the "Data-Project" with an Entity Framework Model and ObjectContext
3. the "Entity-Project" consisting of POCOs

So, to get my app to work I'll have to reference both the Data-Project and the Entity-Project, right?
Or am I getting something wrong?

I am using VS2010 and .NET 4.0
LVL 3
ArikaelAsked:
Who is Participating?
 
Vipul PatelConnect With a Mentor .NET ExpertCommented:
I would like to add something more.

1. Data Layer - Access to database.
2. Object/Entity Layer - Having entities those will be used in the business logic.
3. Business Layer - Have all the business logic.
- Has reference of 1 & 2
4. ASP.NET MVC layer - Presentation logic
- Has reference of 2 & 3.
NOTE: Never use the Entities, declared in layer 2, to create strongly typed views.
5. Service Layer - Used for exposing your business logic/features to third parties.
- Has reference of 2 & 3.

Hope this will help you.
0
 
mrjoltcolaConnect With a Mentor Commented:
If you organize the projects like you mention, then yes, you have to reference both projects from the MVC app.

More typically people don't separate their entities (POCOs) from the data access layer, those are usually one combined project. Only for large apps that may have several backends / frontends would it be worth the trouble to break the entities out from the data layer. But either way, not a major issue.

 
0
 
ArikaelAuthor Commented:
thanks for your answers

@mrjoltcola
If I would do it like you suggested, wouldn't the data access layer and the entities be very tight coupled?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
ArikaelAuthor Commented:
@vrluckyin
"NOTE: Never use the Entities, declared in layer 2, to create strongly typed views."

Why shouldn't I do that?

thanks for your reply :)
0
 
Vipul Patel.NET ExpertCommented:
Because sometime it requires to manipulate the fields.

Let me give you simple example;
In a table, you may save First Name and Last Name separately, but requirement says it would be Firat Name and first character of Last Name.

In the Entity it might be look like;
public class Person{
     public string FirstName {get;set;}
     public string LastName{get;set;}
}

Public class PersonViewModel{
       Person p;
       public void Retrieve(int id)
      {
           //BL code that returns Person object
      }
      public PersonName {
           get{
                    return string.Format("{0} {1}",p.FirstName,p.LastName[0]);
                  }
      }
}

NOTE: This is the very simple example.
0
 
Vipul Patel.NET ExpertCommented:
The ultimate goal is that code should accept changes very easily and rapidly.

You can use your database entities in the views. But I still recommend  to make it separate from entity layer.
0
 
ArikaelAuthor Commented:
ok, so basically I would have to create a Business-Layer-Class for every entity and work with this one?

validation also comes into the business-layer (leave the entities untouched), right?

what is the difference between the business-layer and the service layer, isn't that kinda the same?

thanks
0
 
ArikaelAuthor Commented:
I decided to close the question because the initial question has been answered.

I created a new question which addresses some unanswered/unclear topics.
http://www.experts-exchange.com/Programming/Theory/Software-Design/Q_26990926.html

thanks for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.