Practical Way for Separate Entity Classes (DTO) by EDMX

I have a three-tier application

DAL has an EDMX file that EF6 automatically generated from the database (DB First mode). I also have BLL and UL layers.

But, when I want to use BLL methods in the user interface, I have to add a DAL assembly to the UI layer (due to the returned method types)

List<Person> 

Detects face in EDMX (DAL)] (this is my problem)

How can I separate classes (DTO) from an EDMX file and create as a separate assembly?

How can I prevent the DAL assembly (all EDMX) from being added to the user interface layer?

+4
source share
3

. DAL , " ". .

enter image description here

.

, Person , "" .

. , AutoMappers .

PersonDto, , Person.

public class PersonDto
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

PersonService. - PersonDto ( ). .

public class PersonService
{
    public PersonDto GetPersonById(int id)
    {
         Person person = dbContext.Persons.Find(id);

         // Mapping in action.
         var personDto = new PersonDto()
         {
             FirstName = person.FirstName,
             LastName = person.LastName,
         };

         return personDto;
    }
}

PersonService - , UI, -. .

-, BLL DAL.

+3

, , / (DAL, BLL UI), . AutoMapper, .

100 1000 . .

Code First EF. .

+1

Just move the TT files for POCOs to another project and leave the EDMX TT files in DAL. So you essentially have DTOs / POCO in your own project design, and you can reference them wherever you need them.

+1
source

Source: https://habr.com/ru/post/1540963/


All Articles