我正在 MVC 4 项目中处理 webapi、EF5、Windsor Castle,我有一个问题......我应该在 Get 方法中返回实体(或 DTO)还是应该返回 HttpResponseMessage?更好的方法和更标准的方法是什么?
那么,是这个吗?
[System.Web.Http.HttpGet]
public HttpResponseMessage GetById(long id)
{
var branch = Uow.Branches.GetById(id);
if (branch != null)
{
Request.CreateResponse(HttpStatusCode.OK, branch);
}
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
}
或这个?
[System.Web.Http.HttpGet]
public Branch GetById(long id)
{
var branch = Uow.Branches.GetById(id);
if (branch != null) return branch ;
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
}