0
votes

Design question on entity framework and Domain Layer -

I am creating a new application using the Entity Framework and the DTOs and Entity Objects would have the same structure but there would be quite a bit of business logic involved. So am wondering which would be the best approach from the following, considering the performance and maintainability of the application

Approach 1:

  • Use Entity Objects generated from the T4 template as domain objects
  • create partial classes and add the business logic
  • List item

Expose the Entity Objects to the UI Layer

Approach 2:

  • Create DTOs for the domain layer
  • Add business logic to the DTOs
  • Implement mapping between the Entity -> DTO and DTO -> Entity
  • Expose the DTOs to the UI layer
2
I would say that DTO' should not contain business logic since they should be just data transfers between layers. If it is a completely new app, have you considered Code First approach? And I would suggest to keep business logic without domain objects i.e. entity objects in your case.milagvoniduak
I would recommend asking these types of conceptual ideas about how to program on programmers.stackexchange.com.Erik Philips

2 Answers

0
votes

I personally wouldn't put BL in my domain models or dtos. My controllers knows about my domain layer and also knows about a business layer. My controllers ask/tell my BL to do work and domain models are returned. Controller layer then maps domain model to dto and sends the dto to view.

0
votes

In all the projects I have made I combined the two options. When using a grid with columns from 5-6 tables for example its easier to bind the columns to the properties of a Dto because you could avoid binding to subproperties. It's also harder to create gridfilters if a object has to many subproperties.

So in case of data from multiple tables I guess its better to use Dto's

If you have only data from one table I guess its a bit off overkill to create mappings between an Entity and a Dto with exact the same properties.