views:

38

answers:

1

I have an application where a client communicates with a server side through REST. This is written in .Net, but I guess the question should be independent of this.

Now - I have services such as GetAllCustomers and GetCustomerById. A Customer has references to a potentially big list of Order, so I don't want to pass the Customers references from the GetAllCustomers service. I basically want to return the Customers with their simple data, but no references. Then I will do another service call GetCustomerById to fetch the complete data when a Customer is selected in the client.

The question now is - is there a recommended way of handling this? Using Lazy Loading I can simply pass the object before the references are loaded - and then make sure this isn't used on the client side. But is this ugly? (Also - I got problems communicating lazy loaded objects with REST, but it worked with SOAP - but this is a different question..) I guess I could fetch all data from the database and then delete the references before I return it, but this sure sounds hacky. Also I still get unnecessary load on my database..

So; is there a good solution to this?

+1  A: 

I'm assuming you are transmitting your data with JSON/XML.

Try to lazy-load the objects (server side) and when serializing ignore the Client Order list.

EDIT: You can omit a member from serialization with the attribute [System.Xml.Serialization.XmlIgnoreAttribute]

mcabral
Currently I'm using the default, which is XML. Doesn't seem to work, but ignoring the Client Order list should fix this? I don't do any serialization manually on the server side though. Do I need to do this, or can I fix this with an attribute or something? Thx btw.
stiank81
@stiank81 updated my answer :)
mcabral
Thx for the update, but I guess this will omit the member always. Problem is that I want to omit the references when I do the GetAll, but I need to include it when I fetch the object directly - using GetById etc. So what I need is a way to specify on the service that it should ignore the references which aren't loaded - or something like that.. Do you know about a solution to this?
stiank81