我正在一個MVC 4項目中使用webapi,EF5,Windsor Castle以及我有一個問題......我應該返回實體(或DTO)在Get方法或者我應該返回一個HttpResponseMessage?什麼是更好的方法和更標準的方法來做到這一點?WebApi控制器在實體框架5和MVC 4項目中返回值
那麼,這是嗎?
[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));
}