0

I am new to Entity Framework 6 but would like to use it for the next version of our software.

In my current project i use Csla, which wraps the DAL and BusinessLayer into 1 project.

Is EF doing the same as Csla and creating the DAL and business layer in 1 project? All tutorials online use the Code First approach and bind these objects directly to a MVC web page.

If i use the Database First approach, does this make things different? Would this create only the DAL objects, and would I have to write the business layer version of these objects?

I have read online that people move the Models into a separate project, so you can pass these objects between layers. What would you have in a DAL or BusinessLayer if you did this?

I will mention that we are using SQLServer as our database. I do not think this will change, but never say never.

Gillardo
  • 9,518
  • 18
  • 73
  • 141

1 Answers1

0

I don't know what Csla is. I don't know what you mean by "Is EF doing the same as Csla and creating the DAL and business layer in 1 project?".

In terms of separating your project into layers, it's a good idea.

Making Database First approach shouldn't change anything, in fact not using EF shouldn't change anything too. Because you should use the Repository pattern: http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

Moving model POCOs into a separate project is also a good idea. Why? Consider that you have different projects for the same service: 1) ASP.NET Web Application, 2) ASP.NET WebAPI, 3) WCF Service. When all rely on the same models, your models should be a separate project. Prepare for the worst and you will never regret.

So if you go with the Repository Pattern, your DAL is the project where you implement the Repository pattern.

In business layer, you have business logic. Why do you think it's a problem for business layer if models are put into their own project?

mostruash
  • 4,169
  • 1
  • 23
  • 40
  • So really are the modela like dtos? A way to pass data between layers? If use ef to generate a ur models, what exactly voea into the dal layer? Just the dbcontext object (using code first)? – Gillardo Sep 10 '14 at 20:58
  • Yes, models are for passing around core data for your application/service. If you use repository pattern, repository class becomes the DAL. Otherwise, DbContext is the DAL. – mostruash Sep 10 '14 at 21:56
  • is the repository pattern needed when using EF? Been reading online and some people say it is and others say dbcontext is the repository. Whats your opinion? – Gillardo Sep 11 '14 at 07:59
  • It is almost always better to use repository pattern. Especially for unit tests, you cannot use DbContext. Moreover, if you use dependency injection (IoC), again it is better to use repository pattern. If one day you decide to stop using Entity Framework and replace it with some other library/ORM/pure SQL, you need repository pattern if you want to avoid A LOT of code refactoring. – mostruash Sep 11 '14 at 08:02