How can I pass model to an access data layer/EF Core project from a separate ASP.NET Core Web API project

181 Views Asked by At

I have a design question; thus, no code samples.

I am trying to create an ASP.NET Core Web API project that would use EF Core to communicate with a database. I read about the Data Access design pattern and realize that I have to place a Web API project into a separate project from a data access project (EF Core).

I would reference a data access project (EF Core) from a Web API project and would pass a model to an EF Core project for that model to be mapped to an entity.

My question is, at what project should I conduct the mapping, at the Web API project or at the data access project/EF Core?

If the mapping needs to be done at the data access layer/EF Core, how can I access/recognize the model at the EF Core project since the EF core cannot reference the Web API (no circular reference).

Thank you very much in advance

1

There are 1 best solutions below

0
Abhishek Vyas On BEST ANSWER

James,

One or two layers (Class Library) can be added to handle tasks like

Application Layer

  • Mapping
  • Performing Business Logic,
  • Conversion of DTO to Model and vice versa,
  • Holding Request/Response models.
  • ....

Infrastructure/Core Layer

  • Entities
  • Base Entities/Repositories
  • Common Helper Classes
  • .....

You can refer N-Tier-Architecture-master or eShopOnWeb projects.

enter image description here