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

后端 未结 6 1077
伪装坚强ぢ
伪装坚强ぢ 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:55

    private List GetUsersFromRoles(uint UserRoles) {
      return from u in dc.Users            
             where (u.UserRolesBitmask & UserRoles) != 0
             select u;
    }
    

    UserRoles parameter should be provided, however, as a bit mask, instead of array.

提交回复
热议问题