Question: I have an object with a Flag enum with several possible "uses". The flag enum uses the proper power of 2.

Checking if a variable has a certain flag on, I can do it using the .NET 4 `HasFlag()`

BUT:

If I store that flag combination as a int in database... how can I retrive the objects that have certain flag on using Entity Framework? 

For example, if my object is a "`Contact`" type, I would like to query those of them that are actually "Customers and Friends", being Customers and Friends flags in the `ContactType` Enum.

Answer: 
I doubt any ORM is going to have a way to adapt the HasFlags down to the appropriate SQL code for your DBMS. 

What you are likely going to need to do is either write a stored procedure, or hand-crank the SQL Statement to be executed for this. 

You don't mention what DBMS you're using - but if I assume you're using SQL Server, you are in luck as it has the [& (Bitwise AND) operator](http://msdn.microsoft.com/en-us/library/ms174965.aspx). 

Practical example as T-SQL: 

```
-- Setup Test Data 
DECLARE @Contacts TABLE (id int, contactType int, name nvarchar(MAX)) 

INSERT INTO @Contacts VALUES (1, 0, 'Fred'); -- Not Wanted
INSERT INTO @Contacts VALUES (2, 3, 'Jim');  -- Wanted
INSERT INTO @Contacts VALUES (3, 36, 'Mary');  -- Not wanted
INSERT INTO @Contacts VALUEs (4, 78, 'Jo');  -- Wanted

-- Execute Query
SELECT *
FROM @Contacts
WHERE ContactType & 2 = 2 

```
```
db.Contacts.Where(c => (c.Flag & MyEnum.Flag3) != 0).ToList();

```