?
Solved

MVC, Entitiy Framework and Repository

Posted on 2011-04-30
8
Medium Priority
?
770 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:Arikael
  • 4
  • 3
8 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 200 total points
ID: 35497404
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
 
LVL 5

Accepted Solution

by:
Vipul Patel earned 1000 total points
ID: 35497688
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
 
LVL 3

Author Comment

by:Arikael
ID: 35502909
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Author Comment

by:Arikael
ID: 35506509
@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
 
LVL 5

Expert Comment

by:Vipul Patel
ID: 35506739
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
 
LVL 5

Expert Comment

by:Vipul Patel
ID: 35506765
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
 
LVL 3

Author Comment

by:Arikael
ID: 35506973
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
 
LVL 3

Author Comment

by:Arikael
ID: 35511852
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question