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

Mikhail 41 Reputation points
2023-07-26T02:30:08.7033333+00:00

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

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
729 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,500 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,813 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
326 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,141 Reputation points Microsoft Vendor
    2023-07-26T08:41:09.7333333+00:00

    Hi @Mikhail

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

    Both of the API project and the Data Access Project could use to do the mapping, it depends on your choice.

    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)

    If the mapping needs to be done at the data access layer/EF Core, you have to put the DTO model class in the Data Access Project.

    If the mapping at the API project, the DTO model classes are in the API project and the data base entities are in the Data Access project, before calling the Data Access project's method, you have to convert the DTO model to the database entity, and then execute the related method.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.