<p>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. </p>

<pre><code>var users = from u in dc.Users
            where ((u.UserRolesBitmask &amp; 1) == 1)
               || ((u.UserRolesBitmask &amp; 4) == 4)
               || ((u.UserRolesBitmask &amp; 16) == 16)
            select u;
</code></pre>

<p>I'd like to rewrite this into the method below to returns all the users from the given roles so I can reuse it:</p>

<pre><code>private List&lt;User&gt; GetUsersFromRoles(uint[] UserRoles) {}
</code></pre>

<p>Any pointers on how to dynamically build my query? Thanks</p>

Assuming your UserRoles values are themselves bitmasks, would something like this work?
```
```
private List<User> GetUsersFromRoles(uint[] UserRoles) {
    uint roleMask = 0;
    for (var i = 0; i < UserRoles.Length;i++) roleMask= roleMask| UserRoles[i];
    // roleMasknow contains the OR'ed bitfields of the roles we're looking for

    return (from u in dc.Users where (u.UserRolesBitmask & roleMask) > 0) select u);
}
```
```
There's probably a nice LINQ syntax that'll work in place of the loops, but the concept should be the same.