我遇到WebAPI问题返回空500.WebAPI空500错误
这里是数据类。
public class Comment
{
public int Id { get; set; }
public string Content { get; set; }
public string Email { get; set; }
public bool IsAnonymous { get; set; }
public int ReviewId { get; set; }
public Review Review { get; set; }
}
public class Review
{
public int Id { get; set; }
public string Content { get; set; }
public int CategoryId { get; set; }
public string Topic { get; set; }
public string Email { get; set; }
public bool IsAnonymous { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
这里的代码来从ReviewRepository.cs
public Review Get(int id)
{
return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id);
}
而且从ReviewController.cs
public HttpResponseMessage Get(int id)
{
var category = _reviewRepository.Get(id);
if (category == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK, category);
}
不管我做什么的代码,响应从/ API /评论回/ 1是500错误。调试时,所有加载的评论都是正确的。
我试过GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
,但这并没有帮助。我在这里亏本!
这有助于肯定的到来。对象类型图‘Reviewed.Models.Comment’包含周期,如果参考禁止追踪无法被序列化。 – jcreamer898
+1为了挽救我一些hairloss – havardhu