Keep Getting 'The LINQ expression node type 'Invoke' is not supported in LINQ to Entities' Exception

前端 未结 3 2185
清歌不尽
清歌不尽 2020-12-01 13:45

I am using C# (including Linq) to develop a web application. I have written a generic method to extend Get method of any entity. However when I get the runtime exception \'T

3条回答
  •  萌比男神i
    2020-12-01 14:04

    I beleive the problem is in your And method. You can create the expression yourself using the static Expression methods

    public static IEnumerable GetActive(this ICrudService crudService, Expression> where)
            where T : class, IDeletable
        {
    
    
        var parameter = where.Parameters.FirstOrDefault();
        var property = Expression.PropertyOrField(parameter, "IsDeleted");
        var notProperty = Expression.Not(property);
        var andExpression = Expression.AndAlso(where.Body, notProperty);
    
        var lambda = Expression.Lambda>(andExpression, parameter);
    
    
    
        return crudService.Get(lambda);
    }
    

提交回复
热议问题