WebApi Controller returned value in Entity Framework 5 and MVC 4 project

后端 未结 2 1219
挽巷
挽巷 2021-01-26 08:25

I\'m working on a webapi, EF5, Windsor Castle in a MVC 4 project, and I have a question...should I return the Entity (or DTO) in the Get method or Should I return an HttpRespons

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 08:46

    Depends. However, in your example, since the two versions of the Get action produce the same reponse, I would return the entity Branch instead of the HttpResponseMessage. That is because the framework will help abstract out the actual creation of the HttpResponseMessage so the action focuses more on the business logic.

    If you need more control over the reponse message (i.e. setting a different state code), than I would return the HttpResponseMessage instead.

    Hope this helps.

提交回复
热议问题