Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:17:23+00:00 2026-06-11T19:17:23+00:00

I am using nhibernate 3 and fluent nhibernate I have this enum [Flags] public

  • 0

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>();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:17:24+00:00Added an answer on June 11, 2026 at 7:17 pm

    If you have the following mapping for your TableA type:

    public class TableAMap : ClassMap<TableA>
    {
        public TableAMap()
        {
            ...
            Map(x => x.Permission).CustomType(typeof(Permission)).Not.Nullable();
            ...
        } 
    }
    

    Then you should be able to issue the following query in your repository or wherever you do your data ccess:

    public IList<TableA> GetTableByPermission(Permission permission)
    {
        return Session.Query<TableA>
                      .Where(x => x.Permission == permission ||
                                  x.Permission == Permission.All)
                      .ToList();
    }
    

    Or you can check whether a single TableA instance has got the required permission:

    public bool HasPermission(Guid guid, Permission permission)
    {
        var tableA = Session.Query<TableA>.SingleOrDefault(x => x.Id == guid);
    
        if (tableA != null)
            return (tableA.Permission & permission) == permission;
    
        // Return false or whatever is appropriate.
        return false;
    }
    

    You cannot use your HasFlag() method in the query, NHibernate does not understand how to use that in the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unable to persist a nullable enum using NHibernate with Fluent NHibernate
I have this administration site that is using (Fluent) NHibernate for data access. As
This is how I create Session Factory using Fluent Nhibernate public static ISessionFactory CreateSessionFactory()
I am using NHibernate with fluent mapping. I have the following scenario: public class
I have this table structure and would like to map it using Fluent Hibernate
I have a WPF Application using Fluent NHibernate 1.0 RTM and System.Data.SQLite 1.0.65 that
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
I have a Sharp Architecture based app using Fluent NHibernate with Automapping. I have
Using Nhibernate and Fluent NHibernate for the mapping, I have a parent entity with
I've just started using Fluent NHibernate and have run into the following problem trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.