Click here to Skip to main content
15,900,553 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a design question; thus, no code samples

I am trying to create a Web API Core project that would use an 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 (Mo circular reference)

Thank you very much in advance

What I have tried:

I tried to create a custom mapper to cast an object model but not sure it is a good idea
Updated 25-Jul-23 21:53pm

1 solution

the EF core cannot reference the Web API
You've just answered your own question: the mapping needs to be done in a project which has references to both the entity classes and the DTOs you're mapping to.

Personally, I'd be inclined to move the DTOs to their own project, with no references to anything else; and possibly move the mapping code to its own project as well, with references to the DTOs project and the entities project. That way, you can re-use the DTOs project to create a client for your API, and be sure that the definitions match between the server and client.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900