I am trying to perform a query by example using only a populated ID field (primary key) on my entity but it doesn't seem to be working. Here is my code:
C#
Code:
NewUser user = new NewUser();
user.ID = 1;
Example example = Example.Create(user);
example.ExcludeNulls();
example.ExcludeZeroes();
ICriteria criteria = session.CreateCriteria(typeof(NewUser));
criteria.Add(example);
IList<NewUser> userList = criteria.List<NewUser>();
Mapping File:
Code:
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2" assembly="xxx.Entity" namespace="xxx.Entity">
<class name="NewUser" table="NewUser">
<id name="ID" type="System.Int32" column="NewUserId" unsaved-value="0">
<generator class="identity" />
</id>
<!-- Properties -->
<property name="EmailAddress" type="System.String" column="EmailAddress" not-null="true" length="50" />
<property name="FirstName" type="System.String" column="FirstName" not-null="true" length="50" />
<property name="LastName" type="System.String" column="LastName" not-null="true" length="50" />
<property name="CompanyName" type="System.String" column="CompanyName" not-null="true" length="50" />
<property name="MiddleInitial" type="System.String" column="MiddleInitial" not-null="false" />
<property name="JobTitle" type="System.String" column="JobTitle" not-null="false" length="50" />
<property name="CustomerNumber" type="System.String" column="CustomerNumber" not-null="false" length="50" />
<property name="IndustryTypes" type="System.String" column="IndustryTypes" not-null="false" length="50" />
<property name="SecretAnswer" type="System.String" column="SecretAnswer" not-null="true" length="200" />
<property name="NotificationFlag" type="System.Boolean" column="NotificationFlag" not-null="true" />
<property name="RegisteredDate" type="System.DateTime" column="RegisteredDate" not-null="true" />
<!-- The Address component (class) for a NewUser (allows user.Address.City) -->
<component name="Address" class="Address" insert="true" update="false">
<property name="Street" type="System.String" column="StreetAddress" not-null="false" length="50" />
<property name="City" type="System.String" column="City" not-null="true" length="20" />
<property name="Province" type="System.String" column="Province" not-null="true" length="50" />
<property name="Country" type="System.String" column="Country" not-null="true" />
</component>
<!-- The PhoneNumber component (class) for a NewUser (allows user.PhoneNumber.WorkPhone) -->
<component name="PhoneNumber" class="PhoneNumber" insert="true" update="true">
<property name="WorkPhone" type="System.String" column="WorkPhone" not-null="true" length="10" />
<property name="MobilePhone" type="System.String" column="MobilePhone" not-null="false" length="10" />
</component>
</class>
</hibernate-mapping>
The SQL that's being generated is as follows:
SELECT this_.NewUserId as NewUserId6_0_, this_.EmailAddress as EmailAdd2_6_0_, this_.FirstName as FirstName6_0_, this_.LastName as
LastName6_0_, this_.CompanyName as CompanyN5_6_0_, this_.MiddleInitial as MiddleIn6_6_0_, this_.JobTitle as JobTitle6_0_, this_.CustomerNumber
as Customer8_6_0_, this_.IndustryTypes as Industry9_6_0_, this_.SecretAnswer as SecretA10_6_0_, this_.NotificationFlag as Notific11_6_0_,
this_.RegisteredDate as Registe12_6_0_, this_.StreetAddress as StreetA13_6_0_, this_.City as City6_0_, this_.Province as Province6_0_,
this_.Country as Country6_0_, this_.WorkPhone as WorkPhone6_0_, this_.MobilePhone as MobileP18_6_0_, this_.SecretQuestionId as SecretQ19_6_0_
FROM CustomerPortal.dbo.NewUser this_ WHERE (1=1)
What I would like is for the where clause to be WHERE NewUserId = 1.
Why wouldn't this work and is it possible using the Example query object? I know I could use Session.Load or Session.Get but some limitations prevent me from doing that.