I am using nhibernate 3 and fluent nhibernate
I have this enum
[Flags]
public enum Permission
{
View = 1,
Add = 2,
Edit = 4,
Delete = 8,
All = View | Add | Edit | Delete
}
Now say I want to find all users that have "view" or "all".
How could I do this with nhibernate(linq)?
session.Query<TableA>().Where x.Permission == Permission.View); // does not bring back all
session.Query<TableA>().Where x.Permission.HasFlag(Permission.View); // crashes
Is there away to do this with having to go
session.Query<TableA>().Where x.Permission == Permission.View || x.Permission == Permission.All);
Edit
public class TableAMap : ClassMap<TableA>
{
public TableAMap()
{
Id(x => x.Id).GeneratedBy.GuidComb();
Map(x => x.Permission).Not.Nullable().CustomType<PermissionTypes>();
}
}