Linq query with boolean implemeted as IUserType fails

Description

Boolean values are mapped as implementation of IUserType. The type implementation writes -1 for true values and 0 for false values
to database but allows to use bool properties in the application.
The query:

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

fails with the following exception:

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.

A query using QueryOver :

var pList = Session.QueryOver<Test>().Where( t => t.Active ).List().ToList();

succeeds and produces the correct SQL:

NHibernate: SELECT this_.TEST_ID as TEST1_14_0_, this_.DESCRIPTION as DESCRIPT2_14_0_, this_.ACTIVE as ACTIVE14_0_,
this_.CAT_ID as CAT4_14_0_ FROM T_TEST this_ WHERE this_.ACTIVE = @p0;@p0 = -1 [Type: Int16 (0)]

An complete example with failing test can be found here https://github.com/Belvasis/NHTests

P.S.: Since this is my first issue entry here, i hope that the description and form is correct.

Environment

None

Activity

Show:

Alex Zaytsev May 1, 2017 at 3:42 AM

Closing issues resolved in 4.1.0

Alex Zaytsev April 30, 2015 at 2:54 AM

Merged to master @ c13f70d0d2ef310b8b98515b905ecd0031aa3b0b

The user type should implement IEnhancedUserType to work correctly with the fix.

Alex Zaytsev April 29, 2015 at 11:30 AM

Alex Zaytsev April 29, 2015 at 11:18 AM

Simple workaround:

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

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created August 15, 2011 at 9:21 PM
Updated May 1, 2017 at 3:42 AM
Resolved April 30, 2015 at 2:54 AM
Who's Looking?