Fluent Nhibernate expression to select on flagged enum
- by mbalkema
I have a domain entity that has a flagged enum as a property. The flagged enum is the target audience for the these entities. The user then has a flagged enum value of the entities they should see. I am trying to figure out the correct expression to select entities that meet the target audience for the user.
public class File
{
public virtual TargetAudience TargetAudience { get; set; }
}
[Flags]
public enum TargetAudience
{
Audience1 = 1,
Audience2 = 2,
Audience3 = 4,
Audience4 = 8
}
Expression: (This works when performed on a IList<File>, but doesn't work on a query to the database.)
public Expression<Func<File, bool>> Expression
{
get { return ((x.TargetAudience & UserTargetedAudience) > 0); }
}
Any suggestions would be helpful.