If I have a class Customerthat simply has simple properties (e.g., Nameetc.), then I can create CustomersControllerthat comes from ApiControllerand request Customer objects using the URL /api/customers.
Similarly, if I have a class Orderwith simple properties ( Description, Amount), then I can create OrdersControllerand access it in the same way.
However, if I then add the property to the class Customerin which it is Orderassociated with this Customer:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
... then when I try to execute a query using /api/customers, I get 500 Server Error. I can put a breakpoint in CustomersControllerand see that it calls the correct method and tries to return the value. However, somewhere in the guts of the framework, he cannot turn this into an HTTP response.
It seems like it cannot serialize the information Ordersand / or package it for an HTTP response, but I'm not sure what I need to do to make this happen. Or is it just a case where WebApi is not intended to return complex objects?
Update : my code is here: https://gist.github.com/43ed2f29f8adfb44cef6
Update 2 : additional error information I get:
Server error
The website encountered an error while retrieving http://localhost:1031/api/customers/6.
. : . HTTP 500 ( ): , .
Intellitrace : http://i.imgur.com/iHxJl.png
[ , Intellitrace , . ?]
: ASP.Net Web API, VS, HTTP500