Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing bitwise operations in a LINQ query
    primarykey
    data
    text
    <p>Given the following enum</p> <pre><code>[Flags] public enum Trans{ Purchase =1, Sale=2, All = Purchase | Sale }; </code></pre> <p>And the following class</p> <pre><code>public class Person { public string Name; public Trans TransType; } </code></pre> <p>And the following data structure</p> <pre><code>var people = new List&lt;Person&gt;(); people.Add(new Person {Name="James", TransType = Trans.Purchase}); people.Add(new Person {Name="Nancy", TransType = Trans.Sale}); people.Add(new Person {Name="Heather", TransType = Trans.All}); people.Add(new Person {Name="Duane", TransType = Trans.All}); </code></pre> <p>I am trying to query the list for people meeting certain conditions.</p> <p>To get all people with Trans.Purchase (James, Heather &amp; Duane)</p> <pre><code>var query = from p in people where ( (p.TransType &amp; Trans.Purchase) == Trans.Purchase) select p; </code></pre> <p>To get all people with Trans.Sale (Nancy, Heather &amp; Duane)</p> <pre><code>var query = from p in people where ( (p.TransType &amp; Trans.Sale) == Trans.Sale) select p; </code></pre> <p>What do I need to specify in the where clause of the LINQ query to return everyone with <strong>either</strong> Trans.Purchase, Trans.Sale <strong>or both</strong> (i.e. Trans.All)? (James. Nancy, Heather &amp; Duane)</p> <p><strong>EDIT</strong> Some context - the TransType is stored in a database and am trying to write a screen where the user specified the TransType and a SQL query pulls up the data as specified above</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload