Passing a Linq expression as a string?

前端 未结 3 1028
死守一世寂寞
死守一世寂寞 2021-01-14 03:20

The following code works fine

        using (var ctx = new MyEntities())
        {
            var devices = ctx.Devices
               .Where(x=> x.Devic         


        
3条回答
  •  梦谈多话
    2021-01-14 04:05

    The dynamic linq sample can do much of this, except you drop the lambda notation:

    String expression = "Device == \"TEST\"" ;
    
    //... etc
    
        .Where(expression)
    

    Another example (from the blog):


    (source: scottgu.com)

提交回复
热议问题