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

  • Home
  • SEARCH
  • 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 9126443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:02:40+00:00 2026-06-17T07:02:40+00:00

Table Model: public class UserOwnerShip { public virtual int Id { get; set; }

  • 0

Table Model:

public class UserOwnerShip
{
    public virtual int Id { get; set; }
    public virtual User User { get; set; }
    public virtual City City { get; set; }
    public virtual Company Company { get; set; }
    public virtual UserRole UserRole { get; set; }
    public virtual DateTime RegistryDate { get; set; }
    public virtual bool IsActive { get; set; }
}

Mapping:

internal class UserOwnerShipMap : ClassMap<UserOwnerShip>
{
    public UserOwnerShipMap()
    {
        Id(x => x.Id);
        Map(x => x.IsActive);
        Map(x => x.UserRole).CustomType(typeof(int));
        Map(x => x.RegistryDate);

        References(x => x.User).Not.Nullable();
        References(x => x.City).Nullable();
        References(x => x.Company).Nullable();
    }
}

My EnumConvention Class :

public class EnumConvention : IUserTypeConvention
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum ||
            (x.Property.PropertyType.IsGenericType &&
             x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
             x.Property.PropertyType.GetGenericArguments()[0].IsEnum)
            );
    }

    public void Apply(IPropertyInstance target)
    {
        target.CustomType(target.Property.PropertyType);
    }
}

And UserRole Enum

public enum UserRole
{
    User,
    Operator,
    Manager,
    Manager,
    Admin
}

And my nhibernate config section :

....().Conventions.AddFromAssemblyOf<EnumConvention>())

So when I query :

    IList<UserOwnerShip> userOwnerShip = session.QueryOver<UserOwnerShip>()
                                                    .Where(u => u.UserRole == UserRole.Owner)
                                                    .Where(u => u.IsActive)
                                                    .List<UserOwnerShip>();

I got exception:

Type mismatch in NHibernate.Criterion.SimpleExpression: UserRole expected type System.Int32, actual type XXX.XXX.UserRole (which is enum type class)
  • 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-17T07:02:41+00:00Added an answer on June 17, 2026 at 7:02 am

    If you want to store the int value of the enum, the mapping is simply:

    Map(x => x.UserRole).CustomType<UserRole>();
    

    There’s no need for the EnumConvention.

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

Sidebar

Related Questions

I have a model: public class MyListModel { public int ID {get;set;} public List<User>
Here's my model public class Movie { public int MovieID { get; set; }
I have the following model public class Account { public int Id { get;
This is My model: public class MyModel { public List<long> NeededIds { get; set;
/// Model public class MenuModels { public Int32 MenuId { get; set; } public
I have the following view model: public class BudgetTypeSiteRowListViewModel { public virtual int BudgetTypeSiteID
The model: [Table(RECIPE)] public class Recipe { [Key, Column(ID), DatabaseGenerated(DatabaseGeneratedOption.None), Required] public int ID
Here is a model: Public class Person { [Key] Public int PersonId { get;
I have this code in my Table model: public class DocumentProjectTableModel extends AbstractTableModel{ private
I am using this view model: public class CaseComplaintsViewModel { public int CasesID {

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.