Database Reference
In-Depth Information
Following is the output of the code in Listing 3-34:
Using LINQ...
Patrons who contribute money
Jill Roberts
Ryan Keyes
Steven King
Using Entity SQL...
Patrons who contribute money
Jill Roberts
Ryan Keyes
Steven King
How It Works
In our model, the Patron entity type packs multiple bit flags into a single integer property. A patron can sponsor the
gallery in a number of ways. Each type of sponsorship is represented as a different bit in the SponsorType property.
We represent each of the ways a sponsor can contribute in the SponsorTypes enum . We are careful to assign integers
in power of 2 increments for each sponsor type. This means that each will have exactly one unique bit in the bits of the
SponsorType property.
When we insert patrons, we assign the sponsorship type to the SponsorType property. For patrons that contribute
in more than one way, we simply use the bitwise OR (|) operator to build the bit pattern representing all of the ways
the patron contributes to the gallery.
For the LINQ query, we use the bitwise AND (&) operator to extract the bit for the ContributesMoney flag from the
SponsorType property value. If the result is nonzero, then the patron has the ContributesMoney flag set. If we needed
to find patrons that contribute in more than one way, we would OR all of the SponsorTypes we're interested in together
before we used the AND operator to extract one or more set bits.
The second solution demonstrates the same approach using Entity SQL. Here we use the BitWiseAnd() function
to extract the set bit. Entity SQL supports a full complement of bitwise functions.
3-17. Joining on Multiple Columns
Problem
You want to join two entity types on multiple properties.
Solution
Let's say that you have a model like the one shown in Figure 3-18 . The Account entity type is in a one-to-many
association with the Order type. Each account may have many orders, while each order is associated with exactly one
account. You want to find all of the orders that are being shipped to the same city and state as the account.
 
 
Search WWH ::




Custom Search