Search code examples
odataeager-loadingnetflix

Eager loading with OData


I'm currently working on a small prototype using the Netflix OData api. I would like to always load entities eagerly. In other words, I don't want to "Expand" properties specifically. Rather I would like to just load all the properties of a given entity when that entity is fetched. I'm not asking for design or architectural advice here. I know the implications of doing this. Is there a way to turn on eager loading at the Context level?

Thanks


Solution

  • As Mark noted above, this is not currently possible with any built-in feature of the WCF Data Services. You could inject the $expand into the URL on the client using some code so that it looks like you don't have to do it explicitly though.

    The problem with some generic solution is:

    • Turning this on would transmit lot of data, even though the application might not need it.
    • How many levels should this go? Just one, or two, or many. It can't be unlimited since there might be cycles in the entity graph.

    You could also modify your client-side classes to lazy load the property on access. There's an API DataServiceContext.LoadProperty, so just call that in the right spot.