Entity Framework Dynamic Where Clause

后端 未结 2 724
温柔的废话
温柔的废话 2021-01-02 19:58

I have a query like:

var function = GetSomeExpression();    

using (FooModel context = new FooModel())
{
    var bar = context.Bar.Where(function);
}


        
相关标签:
2条回答
  • 2021-01-02 20:31

    This is way easier then what I was trying before:

    private List<T> GetResults<T>(IQueryable<T> source, 
        Expression<Func<T, bool>> queryFunction)
    {
       return source.Where(queryFunction).ToList<T>();
    }
    
    0 讨论(0)
  • 2021-01-02 20:42

    see this post

    LINQ to entities - Building where clauses to test collections within a many to many relationship

    Edit: after your post update this doesn't seem relevant anymore; I'll leave it in case it's helpful.

    0 讨论(0)
提交回复
热议问题