Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On EF4 actions on entities are actually done via the Business Element layer (BE).

Why do I need the Data Access (DAL) on another layer?

share|improve this question
up vote 2 down vote accepted

It's usefull to wrap entity functions with a service/ DAL layer.
This helps to define a clear distinction between business logic(in a backing bean), and data operations(in a DAL).
So the bean purely deals with business logic, and the data operations as simply called. This means if you later change the data operations, you don't affect the business logic layer(as much). Much like the division that should be between the view and business layer. The view layer should not be doing any business logic(with the exception of validation, and you could argue that could still be a call to the business logic).

You'll also find you will probably use the same data operation repeately throughout your application, so if you have it wrapped in a service class, it's easy to reuse.

My own rule of thumb is, if you have a entity manager in a backing bean, then your doing it wrong.

share|improve this answer
So the whole point is reusability? I mean, with EF4 the BE itself can be the DAL. In theory. – JNF May 25 '12 at 8:10
Yes reusability is key. Indeed a business element could handle the DAL operation, and is fine in a small one off application. As soon as you do the same operation in another element, then it's time to create a DAL. Also for maintenance it makes sense to separate it out. – dmiller2117 May 25 '12 at 14:07
@Davonik You make sense out of it. Thanks! – JNF May 28 '12 at 6:16

It's still good idea to have a separate DAL. In the future, you might want to implement something else (other than Entity Framework). Will you go on looking for all the data access code lying all over the place? nah, I don't think so.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.