我知道这里讨论的方法:
解决Linq to Sql中针对高需求ASP.NET网站的编译查询的常见问题
...但这对我的情况不起作用,因为我得到了:
"从查询返回结果后,不允许设置加载选项."
我使用Codesmith PLINQO脚本生成实体和管理器代码,管理器代码如下所示:
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);
    }
}
我首先尝试将静态DataLoadOptions拖放到Searchmanager类中,如下所示:
public static readonly DataLoadOptions MyOptions = 
    (new Func<DataLoadOptions>(() =>
    {
        var option = new DataLoadOptions();
        option.LoadWith<Search>(x => x.Rule);
        return option; …