I have a Client Server app in the following way.

In the domain some classes have collections of children. Some children reference their parent.
The problem with the is when a request is made to the server for a child object, all other children are returned with the response. In many circumstances it’s very helpful to have access to the parent object from the child and I would prefer not to have to make a seperate request for the parent since that would result in more round trips.
Normally Nhibernates Lazy-Loading would take care of this but the interaction with protobuf-net (or any other serialization) means all the fields are accessed to be serialised. The client has no direct access to the database.
Is it possible to limit the object reference depth in either protobuf-net or Nhibernate in such a way that I can include in the request to the server a flag saying don’t load more than 2 objects deep.
e.g.
Order – Order Item – Delivery Information.
A limit of one on a request for an order would mean don’t load the delivery information. A limit of 0 would mean don’t load the order items.
Altenatively is it possible to optionally stop references being loaded (the limit is either 0 or unlimited) this is more restrictive but possibly more viable to implement.
protobuf-net supports the ShouldSerialize* pattern (in common with several BCL implementations, including the IDE/PropertyGrid, and XmlSerializer).
If you have:
And a corresponding:
Then Whatever is only serialized if ShouldSerializeWhatever returns true. This pattern is entirely name-based. The method can be public or non-public (but XmlSerializer only accepts public methods for this, so keep it public if you are using multiple serializers).