标签: loadoptions

编译LINQ查询和DataLoadOptions ...扭曲!

我知道这里讨论的方法:

解决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);
    }
}
Run Code Online (Sandbox Code Playgroud)

我首先尝试将静态DataLoadOptions拖放到Searchmanager类中,如下所示:

public static readonly DataLoadOptions MyOptions = 
    (new Func<DataLoadOptions>(() =>
    {
        var option = new DataLoadOptions();
        option.LoadWith<Search>(x => x.Rule);
        return option; …
Run Code Online (Sandbox Code Playgroud)

c# linq loadoptions compiled-query

6
推荐指数
1
解决办法
2577
查看次数

标签 统计

c# ×1

compiled-query ×1

linq ×1

loadoptions ×1