How to specify dynamic field names in a Linq where clause?

前端 未结 3 1470
悲哀的现实
悲哀的现实 2020-12-01 10:09

If you create a Filter object that contains criteria for Linq that normally goes in a where clause like this:

 var myFilterObject = FilterFactory.GetBlank();         


        
3条回答
  •  情深已故
    2020-12-01 10:50

    I suggest you have a look at Dynamic Query in the Linq to SQL examples. You can use that to write conditions in "plain text", e.g.:

    var employees = db.Employee.Where("Salary < 40000").Select(...);
    

    To clarify: These extensions essentially build the same expression trees out of the string that you normally construct via lambdas, so this isn't the same as writing raw SQL against the database. The only disadvantage is that you can't use the query comprehension syntax (from x in y etc.) with it.

提交回复
热议问题