.NET Core - Data Retrieval issue

Pratham Jain 221 Reputation points
2023-03-21T09:03:26.03+00:00

Hi All,

I am developing an application in .NET Core with Angular. I have a scenario where I am returning all the Employee data by EmployeeId from several Employee database tables using .NET Core WebAPI. I am using DbContext in Repository class to fetch all the data from Employee tables which is fetched in employee DB entities.

Now my concern is that should I return these DB entities directly to client or should I create a new Model/ViewModel in WebAPI to return data to Angular client.

Note: I also have few additional properties which are calculated from returned entities properties from DB.

Please advise me the best way to achieve the same.

Thanks and Regards,

Pratham

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,502 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,141 Reputation points Microsoft Vendor
    2023-03-22T05:55:52.7633333+00:00

    Hi @Pratham Jain

    Now my concern is that should I return these DB entities directly to client or should I create a new Model/ViewModel in WebAPI to return data to Angular client. Note: I also have few additional properties which are calculated from returned entities properties from DB.

    I prefer to the create a new Model/ViewModel in WebAPI to return data to Angular client.


    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 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.