Can I generate a linq expression dynamically in C#?

后端 未结 4 992
遥遥无期
遥遥无期 2021-01-22 08:40

I\'ve currently got a piece of Linq that looks something like this ;

List childrenToBeRemoved = this.ItemsSource.Where(o => o.ParentID == \"123         


        
4条回答
  •  花落未央
    2021-01-22 09:43

    it should not matter if query is dynamic linq or not

    Expression> predicate = x => x.Id == myvalue;
    from entity in _context.Entities.Where(predicate)
    select entity;
    

    Check out PredicateBuilder of LinkKit @ http://www.albahari.com/nutshell/linqkit.aspx there are enough examples there as well

    Responsibility of translation of an expression to corresponding sql lies with the linq provider, so make sure the provider you are using supports the relevant aspects

提交回复
热议问题