When add a restriction on a particular string property with a value
of "true" or "false", NH (2.1.2.4000) changes it to a bit value. See
example class, hbm, query and resulting SQL. Note in the last snip,
the line "WHERE this_.SettingValue = 1" should read "WHERE
this_.SettingValue = 'true'. If I change the restriction from "true"
to "poop", the NH correctly surrounds poop with quotes. My conclusion
is that NH tries to convert the string value to boolean, and if it
can, it does so using the value substitution from the session factory
configuration. This is curious, since NH knows that column is a
string from the mapping, so why would it need to guess? Is there a
way to inform NH not to do this?
namespace MYAPP.Core.Domain
{
public class EmployeeSetting
{
public virtual int ID { get; set; }
public virtual string SettingValue { get; set; }
public virtual Employee Employee { get; set; }
public virtual SettingType SettingType { get; set; }
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MYAPP.Core" namespace="MYAPP.Core.Domain">
<class name="MYAPP.Core.Domain.EmployeeSetting,MYAPP.Core"
table="EmployeeSetting">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="SettingType" column="SettingType"
type="MYAPP.Core.Domain.SettingType, MYAPP.Core" not-null="false" />
<property name="SettingValue" column="SettingValue" type="string"
not-null="false" />
<many-to-one name="Employee" column="EmployeeID"
class="MYAPP.Core.Domain.Employee,MYAPP.Core.Domain"/>
</class>
</hibernate-mapping>
IList<EmployeeSetting> es = _EmployeeSettingDAO.GetSession()
.CreateCriteria<EmployeeSetting>()
.Add(Restrictions.Eq("SettingValue", "true"))
.Add(Restrictions.Eq("SettingType", SettingType.ReceiveAlerts))
.List<EmployeeSetting>();
SELECT this_.ID as ID8_0_,
this_.SettingType as SettingID8_0_,
this_.SettingValue as SettingV3_8_0_,
this_.EmployeeID as EmployeeID8_0_
FROM EmployeeSetting this_
WHERE this_.SettingValue = 1 /* @p0 */
and this_.SettingType = 1 /* @p1 */
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.