3

I usually create dataset as DAL, and BLL INSIDE the original project.

After I learned Entity Framework, I know that business logic layer are commonly created in separated project(class library).

However, ASP.NET site has no corresponding tutorial.

For this reason, I'm quite confused when I create BLL especially during referencing.

  1. In order to complete the BLL classes, am I supposed to directly add reference like this?

enter image description here

and then access to the entity with USING statement:

enter image description here

However, the presentation layer in main project which accesses BLL might need to reference back to BLL project. I saw some of the samples putting the entire BLL project's DLL file in the main project.

What's the correct way to reference BLL and Main project, or just reference as above?

Are there any good tutorial I can study from?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Ivan Li
  • 1,850
  • 4
  • 19
  • 23

1 Answers1

6

I normally setup a data access project, setup a business project that has a reference to the data access project, and a web project with references to both the data access and business project. With entity framework, all of the generated classes are in the data access layer.

I normally use the repository pattern, which all of my repositories are in the business layer (could be in the data access layer too), and return the entity framework entities to the caller, which is an object in the presentation layer (an MVC controller, or an MVP presenter, or the code-behind of an asp.net web form, depending on what you are using).

halfer
  • 19,824
  • 17
  • 99
  • 186
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • 2
    Even better would be to separate (push out) the entities (model) into a new project. That way your web layer only references the business layer and the model (entities), without a direct reference to the data access layer. This is of course if you only use the data access (repositories) in your business layer, and don't use them directly from the web layer. – e36M3 Dec 31 '12 at 19:40
  • 1
    I agree that there are benefits to doing that, but there are also added complexities. It really depends on the size and needs of the project to determine whether that is beneficial. It's very quick and easy just to push an entity from the context through the repository into the web layer, and let them all be attached. – Brian Mains Dec 31 '12 at 19:49