Fluent Nhibernate expression to select on flagged enum

Posted by mbalkema on Stack Overflow See other posts from Stack Overflow or by mbalkema
Published on 2010-04-07T13:40:19Z Indexed on 2010/04/07 13:43 UTC
Read the original article Hit count: 279

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about c#