我遇到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