How do you add dynamic 'where' clauses to a linq query?

后端 未结 6 1064
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 07:19

I\'ve got a User table with a bitmask that contains the user\'s roles. The linq query below returns all the users whose roles include 1, 4 or 16.

var users          


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 07:51

    There are a couple of ways you can do this:

    LINQ Dynamic query libraries: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    Expression Trees & Lamda expressions: http://msdn.microsoft.com/en-us/library/bb882637.aspx

提交回复
热议问题