简体   繁体   English

Telerik OpenAccess为每个函数调用生成相同的查询

[英]Telerik OpenAccess generating the same query for every function call

I'm using a Generic Repository like pattern to fetch data. 我正在使用通用存储库之类的模式来获取数据。 There are 100+ entities so creating a separate repository for each is not really an option. 有100多个实体,因此实际上不能选择为每个实体创建单独的存储库。 here are a few functions from the same class: 这是同一类的一些函数:

    public int Count(Func<TEntity, bool> x=null)
    {
        return x == null ?
            mgr.CTX.GetAll<TEntity>().Count() :
            mgr.CTX.GetAll<TEntity>().Where(x).Count();
    }

    public TEntity One(Func<TEntity, bool> x)
    {
        return mgr.CTX.GetAll<TEntity>().Where(x).Take(1).FirstOrDefault();
    }

    public IQueryable<TEntity> All(Func<TEntity, bool> x=null)
    {
        return x == null ?
            mgr.CTX.GetAll<TEntity>() :
            mgr.CTX.GetAll<TEntity>().Where(x).AsQueryable<TEntity>();
    }

The problem is no matter which function is call, the Sql profiler shows the same 问题是无论调用哪个函数,SQL事件探查器都显示相同的问题

Select [columns] from [table] 从[表格]中选择[列]

I suppose when using Take(1) or Count() or Where() the query should be made accordingly using Count() , Top or Where clauses of Select but these functions have absolutely no effects on query generation. 我想当使用Take(1)或Count()或Where()时,应使用Select的 Count()TopWhere子句相应地进行查询,但是这些函数对查询生成完全没有影响。 Apparently, every operation seems to be performed in memory after fetching all the data from server. 显然,从服务器获取所有数据后,似乎所有操作都在内存中执行。

Guide me if there is something wrong with the way I'm accessing it or this is the normal behavior of telerik? 如果我访问它的方式有问题,或者这是telerik的正常行为,请引导我。

I believe you are victim of a subtle difference between definitions of LINQ extension method - in-memory ones use Func<> while SQL-bound use Expression<> as parameter type. 我相信您是LINQ扩展方法定义之间的细微差异的受害者-内存中的定义使用Func<>而SQL绑定的使用Expression<>作为参数类型。
My suggestion is to change All(Func<TEntity, bool> x=null) to All(Expression<Func<TEntity, bool>> x=null) 我的建议是将All(Func<TEntity, bool> x=null)更改为All(Expression<Func<TEntity, bool>> x=null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM