I know about the method discussed here:
Solving common problems with Compiled Queries in Linq to Sql for high demand ASP.NET websites
... but this doesn't work for my situation as i get a :
"Setting load options is not allowed after results have been returned from a query."
I am using Codesmith PLINQO scripts to generate entities and manager code, and the manager code looks something like this:
public partial class SearchManager
{
#region Query
// A private class for lazy loading static compiled queries.
private static partial class Query
{
internal static readonly Func<MyDataContext,IOrderedQueryable<Search>>
GetAll = CompiledQuery.Compile(
(MyDataContext db) =>
from s in db.Search
orderby s.Name
select s);
}
#endregion
public IQueryable<Search> GetAll()
{
return Query.GetAll(Context);
}
}
I first tried dropping a static DataLoadOptions into the Searchmanager class like this:
public static readonly DataLoadOptions MyOptions =
(new Func<DataLoadOptions>(() =>
{
var option = new DataLoadOptions();
option.LoadWith<Search>(x => x.Rule);
return option;
}))();
... then providing it to the Context in the GetAll method like:
public IQueryable<Search> GetAll()
{
Context.LoadOptions = MyOptions;
return Query.GetAll(Context);
}
...and that gave me the error i noted above. Is this because the query is already compiled, and thus can't have "extra" DataLoadOptions's added? If so, how would it be possible to apply the DataLoadOptions prior to the the query being compiled?