C# Linq set expersion命令在exernall方法中的位置和参数

C# Linq set expersion命令在exernall方法中的位置和参数,c#,linq,C#,Linq,我尝试设置expersion参数comand linq where in out 例如: private Expression<Func<SanadItem, bool>> SanadItemWhere() { return xx => xx.IdCol == 1; } var queryCalac2 = context.sanad.Select(x => new {

我尝试设置expersion参数comand linq where in out 例如:

    private Expression<Func<SanadItem, bool>> SanadItemWhere()
    {
        return xx => xx.IdCol == 1;
    }

        var queryCalac2 = context.sanad.Select(x => new
        {
            dd = x.Col.AsQueryable()
                .Where(SanadItemWhere())
                .GroupBy(b => b.IdCol)
                .Select(y=>new { bed= y.Sum(c=>c.Bed) })
        });
 ...
此代码工作正常,但当我想从旧选择发送参数时,我得到错误Linq 1025:

    private Expression<Func<SanadItem, bool>> SanadItemWhere(Sarfasl s)
    {
        return xx => xx.IdCol == s.Id;
    }

    public IEnumerable<TarazResult> GetTaraz(IQueryable<Sarfasl>all, TarazAzmayeshiView model)
    {            
        var queryCalac2 = Context.Sarfasl.Select(x => new
        {
            dd = x.Col.AsQueryable()
                .Where(SanadItemWhere(x))
                .GroupBy(b => b.IdCol)
                .Select(y=>new { bed= y.Sum(c=>c.Bed) })
        });
什么是语境?您使用实体框架吗

实体框架将把LINQ查询编译成SQL查询。SanadItemWhere函数无法转换为SQL运算符。你需要帮助它

一般来说,有两种解决方案:

如果可能,使用[EdmFunction]属性将sandItemWhere函数绑定到用户定义的SQL函数read:

通过组合主查询动态生成查询。其中….GroupBy….选择。。。还有SanadItemWhere表达式

下面是关于第二种解决方案的一些提示

首先,将SaaDaTimeSoad视为表达式。 使用ExpressionVisitor组合表达式请参见: