Meelfan Bmfp
Meelfan Bmfp

Reputation: 605

Caching linq 2 sql entities and related entities

I'm caching the result of my linq 2 sql queries and I was hopeful that the related entities were also loaded and cached in the memory of my application(asp.net application).

Well this did not happen. The related entities were null.

Question: how do I make sure when I cache an entity Product the the related Category is also cached? Can this be done without having to explicitly cache the related category? Any comment will be highly appreciated.

thanks in advance M

Upvotes: 1

Views: 119

Answers (1)

Pleun
Pleun

Reputation: 8920

You can use LoadOptions on the Datacontext to make sure they are automatically loaded

DataLoadOptions options = new DataLoadOptions(); 
options.LoadWith<Product>(c => c.OrderDetails); 
db.LoadOptions = options; 

This example loads OrderDetails with products immediately.

Upvotes: 1

Related Questions