I have a problem with returning a WebAPI to an empty 500.
Here are the data classes.
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; } }
Here is the code from ReviewRepository.cs
public Review Get(int id) { return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id); }
And the code from 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); }
No matter what I do, the answer from / api / reviews / 1 is a 500 error. When debugging, the category matches all the comments loaded.
I tried GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; , but it did not help. I'm here in difficulty!
source share