I have a .Net application split in client and server sides, and the server provides REST services (using WCF). I have services definitions like these:
[WebGet(UriTemplate = "/Customers/{id}")]
Customer GetCustomerById(string id);
[WebGet(UriTemplate = "/Customers")]
List<Customer> GetAllCustomers();
The Customer class and its friends are mapped to a database using Fluent NHibernate, with Lazy Loading. If I return from the service outside the Session-scope the service call will fail as it can't serialize the referenced lazy loaded Orders property (see class def at the end). The problem is that I need this to be lazy loaded as I don't want my GetAllCustomers
-service to fetch all the referenced Orders. So what I want to do is to notify the serializer somehow such that it doesn't attempt to serialize Orders on GetAll. But please note that the same property must be serialized on GetCustomerById - so I must specify this on the service. Can this 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; }
// ++
}