Database Reference
In-Depth Information
3-16. Using Bitwise Operators in a Filter
Problem
You want to use bitwise operators to filter a query.
Solution
Let's say that you have an entity type with an integer property that you want to use as a set of bit flags. You'll use
some of the bits in this property to represent the presence or absence of some particular attribute for the entity. For
example, suppose you have an entity type for patrons of a local art gallery. Some patrons contribute money. Some
volunteer during gallery hours. A few patrons serve on the board of directors. A few patrons support the art gallery in
more than one way. A model with this entity type is shown in Figure 3-17 .
Figure 3-17. A Patron entity type with a SponsorType property that we use as a collection of bit flags indicating the
sponsorship type for the patron
We want to query for patrons and filter on the type of sponsorship provided by the patron. To do this, follow the
pattern in Listing 3-34.
Listing 3-34. Using Bitwise Operators in a Query
static void Main()
{
RunExample();
}
[Flags]
public enum SponsorTypes
{
None = 0,
ContributesMoney = 1,
Volunteers = 2,
IsABoardMember = 4
};
 
Search WWH ::




Custom Search