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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:08:56+00:00 2026-06-02T00:08:56+00:00

In my project I use a IUserType (BooleanM1) that handles boolean values and writes

  • 0

In my project I use a IUserType (BooleanM1) that handles boolean values and writes -1 for true and 0 for false values to the database. So far everything works well. The mapping looks like
this:

<property name="Active" column="ACTIVE" type="Core.Persistence.NH.Types.BooleanM1,Core.Test"/>

So if I do a query like the following

var pList = Session.Query<Test>().Where( c => c.Active ).ToList();

an exception is thrown:

NHibernate.QueryException: Unable to render boolean literal value [.Where[Core.Test.Domain.Test]
(NHibernate.Linq.NhQueryable`1[Core.Test.Domain.Test], Quote((c, ) => (c.Active)), )] 
---> System.InvalidCastException: Das Objekt des Typs "NHibernate.Type.CustomType" kann nicht 
in Typ "NHibernate.Type.BooleanType" umgewandelt werden.

The BooleanM1 implementation is like this:

{
  public class BooleanM1 :  IUserType
  {
     public bool IsMutable
     {
       get { return false; }
     }

     public Type ReturnedType
     {
        get { return typeof(bool); }
     }

     public SqlType[] SqlTypes
     {
        get { return new[]{NHibernateUtil.Int16.SqlType}; }
     }

     public object NullSafeGet(IDataReader rs, string[] names, object owner)
     {
        var obj = NHibernateUtil.String.NullSafeGet(rs, names[0]);

        if(obj == null ) return false;

        return ((string)obj == "-1" || (string)obj == "1") ? true : false;
     }

     public void NullSafeSet(IDbCommand cmd, object value, int index)
     {
        if(value == null)
        {
          ((IDataParameter) cmd.Parameters[index]).Value = DBNull.Value;
        }
        else
        {
          ((IDataParameter) cmd.Parameters[index]).Value = (bool)value ? -1 : 0;
        }
     }

     public object DeepCopy(object value)
     {
        return value;
     }

     public object Replace(object original, object target, object owner)
     {
        return original;
     }

     public object Assemble(object cached, object owner)
     {
       return cached;
     }

     public object Disassemble(object value)
     {
        return value;
     }

     public new bool Equals(object x, object y)
     {
       if( ReferenceEquals(x,y) ) return true;

       if( x == null || y == null ) return false;

       return x.Equals(y);
     }

     public int GetHashCode(object x)
     {
        return x == null ? typeof(bool).GetHashCode() + 473 : x.GetHashCode();
     }
}

Is this an known bug in the linq provider or is there something wrong with my UserType? Any help is appreciated.

  • 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-02T00:08:57+00:00Added an answer on June 2, 2026 at 12:08 am

    I had a similar issue with a UserType that does pretty much the same thing. I found that explicitely stating the equality in my queries resolved the problem.

    Try going from:

    var pList = Session.Query<Test>().Where( c => c.Active ).ToList();
    

    to:

    var pList = Session.Query<Test>().Where( c => c.Active == true ).ToList();
    

    For some reason NHibernate’s Linq provider is then able to figure it out.

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

Sidebar

Related Questions

Several parts (a WinForms app for exmaple) of my project use a DAL that
In our project we use test data that is stored inside .sql files that
In my iPhone project,I use Odata Service to get data from SQL Server database
When I compile our project use Delphi 2010 Trial, there has a fatal error
I try to run my project in windows. Project use android ndk. I install
In a project i use the following code to open a window: window.open(href, 'mysite'
In my project I use quite complicated (and nested) collection: List<Pair<List<Pair<double>>, double>> myCollection As
In our project we use jQuery 1.4.4 and jQuery UI 1.8.7 now. But we
At my project I use Spring Security and GWT with url-like internationalization (http://....html?locale=en). Login
In a project we use PartialView and View on the same action, depending how

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.