Skip to content

NH-3887 - Linq Query incorrect when using & operator #1348

Closed
@nhibernate-bot

Description

@nhibernate-bot

martin.hoelbling created an issue — 7th July 2016, 11:47:34:

Example:

public List<T> Get<T>(Expression<Func<ITypeChangeReason, T>> converter, ChangeReasonUsage? usage = null)
{
    var temp = Session.Query<ITypeChangeReason>()
        .Where(x => x.DeletedDate == null);

    if (usage.HasValue)
    {
        temp = temp.Where(x => (x.Usage & usageValue.Value) == usageValue.Value);
    }

    return temp.Select(converter).ToList();
}

This linq-query sometimes results in:

select typechange0_.ID           as col_0_0_,
       typechange0_.Name         as col_1_0_,
       typechange0_.ShortName    as col_2_0_,
       typechange0_.[Order]      as col_3_0_,
       typechange0_.UpdateMode   as col_4_0_,
       typechange0_.Usage        as col_5_0_,
       typechange0_.Restrictions as col_6_0_
from   TypeChangeReason typechange0_
where  (typechange0_.Mandator & -1 /* @p0 */) != 0
       and (typechange0_.DeletedDate is null)
       and typechange0_.Usagetypechange0_.Usage & 8 /* @p1 */ = 8 /* @p2 */

This behaviour is not deterministic. After a application-restart the query works fine.

Hbm

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Ilogs.Products.Moment.Data.Model">
	<class name="Ilogs.Products.Moment.Data.Model.TypeChangeReason" batch-size="50" table="TypeChangeReason" > abstract="false" >
		<id name="ID" type="System.Int32" column="ID">
			<generator class="hilo"/>
		</id>
		<property name="CreatedBy" column="CreatedBy" type="System.String" not-null="true" />
		<property name="CreatedDate" column="CreatedDate" type="Timestamp" not-null="true" />
		<property name="DeletedDate" column="DeletedDate" type="Timestamp" not-null="false" />
		<property name="Mandator" column="Mandator" type="System.Int32" not-null="true" />
		<property name="ModifiedBy" column="ModifiedBy" type="System.String" not-null="true" />
		<property name="ModifiedDate" column="ModifiedDate" type="Timestamp" not-null="true" />
		<property name="Name" column="Name" type="System.String" not-null="true" length="255" />
		<property name="Order" column="[Order]" type="System.Int32" not-null="false" />
		<property name="RecordWriteRight" column="RecordWriteRight" type="System.Int32" not-null="true" />
		<property name="Restrictions" column="Restrictions" not-null="true" />
		<property name="ShortName" column="ShortName" type="System.String" not-null="true" length="255" />
		<property name="UpdateMode" column="UpdateMode" not-null="true" />
		<property name="Usage" column="Usage" not-null="true" />
	</class>
</hibernate-mapping>

martin.hoelbling added a comment — 7th July 2016, 11:49:06:

The Exception is:
could not execute query
< select typechange0*.ID as col_0_0_, typechange0_.Name as col_1_0_, typechange0_.ShortName as col_2_0_, typechange0_.[Order> as col_3_0_, typechange0_.UpdateMode as col_4_0_, typechange0_.Usage as col_5_0_, typechange0_.Restrictions as col_6_0_ from TypeChangeReason typechange0_ where (typechange0_.Mandator & @p0) != 0 and (typechange0_.DeletedDate is null) and typechange0_.Usagetypechange0*.Usage & @p1=@p2 ]
Name:p2 - Value:8 Name:p3 - Value:8
<SQL: select typechange0*.ID as col_0_0_, typechange0_.Name as col_1_0_, typechange0_.ShortName as col_2_0_, typechange0_.[Order> as col_3_0_, typechange0_.UpdateMode as col_4_0_, typechange0_.Usage as col_5_0_, typechange0_.Restrictions as col_6_0_ from TypeChangeReason typechange0_ where (typechange0_.Mandator & @p0) != 0 and (typechange0_.DeletedDate is null) and typechange0_.Usagetypechange0*.Usage & @p1=@p2]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions