Using Context with LINQ

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 02-Nov-2009 03:33:42   

Hello,

i just noticed this "Context" object existed. My understanding of it is that it can be used to cache entities.

In the context of a linq query you can set a context to the linq meta data object in use. I was wondering if there was any way to have finer control over it.

For example I want a certain query to put only entities of a specific type into the context (these entities are prefetched).

Can it be done?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 02-Nov-2009 11:18:25   

Set the metaData.ContextToUse just before the specific query. And reset it to null just after it.

Docs example:

// metaData is a LinqMetaData instance metaData.ContextToUse = new Context();

// this query will use the context set var q = from c in metaData.Customer where ... select ...

// resetting metaData.ContextToUse = null;

// this query won't use the context previously set, as the metaData's property // is null. var q = from o in metaData.Order ...

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 05-Nov-2009 02:15:59   

What if i wanted it the store only entities of a specific type.

Say I am performing a query with a prefetch, and I want it to store only the prefetched"State" entities for example. Is that possible?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 05-Nov-2009 13:49:02   

What you want isn't possible in the current version. Context is also not to be used as a cache, it's usable for uniquing, not a cache.

Frans Bouma | Lead developer LLBLGen Pro