I have a enum:
[Flags]
public enum EmailType
{
PasswordRecovery = 1,
Activation = 2,
SendTicket = 4
}
For example, in a table we have value equals 3 that means - PasswordRecovery
, Activation
.
This is my query:
var emailType = EmailType.PasswordRecovery;
return Database.EmailSettings.FirstOrDefault(es => es.EmailType == (int)emailType);
Of course this query not works properly:3 == 1 => false
.
How to filter properly?
Thanks.
UPDATE:
I'm using Flags
attribute because there is one more application written with XAF (devexpress framework) and I have one feature in UI that required Flags
attribute.
int emailType = (int)EmailType.PasswordRecovery;
return Database.EmailSettings.FirstOrDefault(es => (es.EmailType & emailType) == emailType);
Edit: I added a cast since es.EmailType
is and int
.