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 645377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:29:43+00:00 2026-05-13T21:29:43+00:00

How can I construct a query against an custom IUserType field in NHibernate? More

  • 0

How can I construct a query against an custom IUserType field in NHibernate?

More specifically:
I’m working on a brownfield application. I have a field in the database called “State” which contains a char representing what state a given object is in.

In my code I want this to be represented as an enum so I’ve created an enum with a value for each state and created an IUserType that converts from the db’s char value to my enum and back for selects & updates.

I want to construct a query that looks something like this:

session.CreateCriteria<MyType>().Add(Expression.Eq("State", StateEnum.Complete))

However, that query throws an exception:

could not resolve property: State of: MyNamespace.MyType

presumably because NHibernate doesn’t know how to do a select against the DB’s char field given a StateEnum type.

  • 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-05-13T21:29:43+00:00Added an answer on May 13, 2026 at 9:29 pm

    Your class and mapping should be something like the following:

    class MyType
    {
        public virtual StateEnum State { get; set; }
    }
    
    <class name="MyType">
        <property name="State" type="MyNamespace.MyEnumUserType, MyDll" />
    </class>
    

    NHibernate has 3 built in mappers for enum:

    • PersistentEnumType maps to an int column, and is not declared in the mapping.
    • EnumStringType maps to a varchar column. The values are the ToString() values of the enum.
    • EnumCharType maps to a char column. The values are the result of (char) (int) enumvalue.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the c# driver for MongoDB I can easily construct a query against which
How can we construct a query to search for particular field to be not
How can I construct an object using a query if I also need to
How can we construct sql query with following constraint. For each record where is_queue_empty=1
I have a (rails 3) application that allows users to query for books. I
Is it possible to construct a query so that I can find out what
H. I'm trying to construct linq query that dynamicly generate query for custom ordering
I am trying to construct a query that is a bit more complicated than
Given an EmployeeId, how can I construct a Linq to Sql query to find
Is there any way I can construct an new object from the given object

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.