views:

286

answers:

2

Hi I've been given the task of creating an N-Teir website using the Entity Framework 4 and am coming up against some brick walls, more than likely in my knowledge.

My plan so far was to have these layers

Website (application layer),
What I'm calling Name.Framework (BLL),
Name.Data (DAL),
Name.Entities (contains POCO classes and other struct classes used in website/bll,
Name.Common (utility class)

I've tried to use the repository class, but am struggling to make things work how I thought they would. Below are a few examples of what I'm getting stuck on.

If I want to use .include() would this be in my Repository or is this the responsibilty of the business layer? (and I have no idea how this would work in the BLL)

Same question for .Order()? As I understood it this would need to be in repository or at least passed into the repo in some way?!?

Should I be using the BLL to pass in the Context to the repository/data layer? At the moment when I get an entity from the Data layer any navigation properties that weren't referenced in the repo just come back with 'Object Context Disposed', should the Business layer still hold the context etc so that this wouldn't happen?

Or to summarize this HELP!!!

I need to have this in some sort of order by tomorrow (eek!) as the project leader wants to know if we are going to continue with Entity Framework or move to NHibernate as in-house we have more knowledge of it.

Thanks for any help or suggestions Matt

A: 

I'm currently working on a web hobby project with EF4 Code-Only, where I have the following structure ([name] being the name of my project):

  • [name].Web - An ASP.NET MVC 2 project
  • [name].Web.Models - Custom view models, along with AutoMapper mappings from my entity objects
  • [name].Models - My POCO classes, and interfaces for repositories
  • [name].DataAccess - Some interfaces related to data access, for example IUnitOfWork
  • [name].DataAccess.EF - All Entity Framework related classes and interfaces

I also have a test project for each of the above, plus a couple of projects with helpers and extensions for the tests.

It might be relevant to mention that part of the purpose of this hobby project is for me to learn how to use EF4 with some design patterns of my own choice (the ones that concern EF in this project are the Repository Pattern and the Unit of Work pattern). Another partial purpose is to build up a code base that I can re-use in later projects, and this has affected the division between projects in my application - for example, if I wasn't concerned with re-use, I'd probably have all data access related classes in one project instead of two.

Tomas Lycken
A: 

I've implemented a basic EF, poco, Repository, UnitOfWork architecture largely following this article here:

http://devtalk.dk/CommentView,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx

I found it to be very helpful in these endeavors. Don't know if it helps you but others might be interested in the link.

kdawg