I have a .Net application separated on the client and server side, and the server provides REST services (using WCF). I have service definitions like these:
[WebGet(UriTemplate = "/Customers/{id}")]
Customer GetCustomerById(string id);
[WebGet(UriTemplate = "/Customers")]
List<Customer> GetAllCustomers();
The Customer class and its friends map to a database using Fluent NHibernate with Lazy Loading. If I return from a service outside the scope of the session, the service call will fail because it cannot serialize the link lazy loaded property Orders (see def class at the end). The problem is that I need it to be lazily loaded, since I do not want my GetAllCustomersservice to receive all the specified Orders. Therefore, I want to somehow notify the serializer so that it does not try to serialize GetAll Orders. But keep in mind that the same property must be serialized to GetCustomerById - so I have to specify this in the service. It can be done?!
Classes:
public class Customer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Order> Orders { get; set; }
}
public class Order
{
public virtual int Id { get; set; }
}