Bit (sorry) confused about how to use bitwise operators with Entity Framework.
A recent requirement has necessetated that we alter an enum from a series of sequential integers into a bitwise enum. So:
[Flags]
public enum AdminLevel
{
None = 0,
Basic = 1,
Partial = 2,
Full = 4
}
We originally stored this as an int column in the database. It's still an int, of course, but I'm having trouble seeing how I can perform selections based on more than one possible enum value. For example this code:
public string GetAdminEmails(AdminLevel adminlevel)
{
using (IRepository r = Rep.Renew())
{
string[] to = r.GetUsers().Where(u => u.AdminLevel >= (int)adminlevel).Select(u => u.Email).ToArray();
return string.Join(",", to);
}
}
Would return all the admin levels including and above the one supplied. If I want more than one admin level, I now have to call it like this:
GetAdminEmails(AdminLevel.Partial | AdminLevel.Full);
But obviously I can't convert that to an int and use greater than any more. Is there a neater way of handling this change than a series of flow control statements?