Hi,
I'm using NHibernate v1.0.2.0, SQL Server 2000, .Net 1.1 and VB.NET.
I'm trying to save just the date part of a DateTime property to a DATETIME database column. From what I've read, it sounds like I should be able to use the NHibernate type = date (as opposed to DateTime or timestamp) to save just the date part of the property. Is this assumption correct? If so, can someone help me with the setup?
VB.NET Property definition
Code:
Private _LastLogon As DateTime
Public Property LastLogon() As DateTime
Get
Return _LastLogon
End Get
Set(ByVal Value As DateTime)
If Value <> _LastLogon Then
_LastLogon = Value
_IsChanged = True
End If
End Set
End Property
Mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="com.v1s.v1web.entities.User, V1WebBizEntities" table="users_vb">
<id name="LogonID" column="LogonID" type="String">
<generator class="assigned" />
</id>
<property name="Name" column="Name" type="String" />
<property name="Password" column="Password" type="String" />
<property name="EmailAddress" column="EmailAddress" type="String" />
[b]<property name="LastLogon" column="LastLogon" type="Date" />[/b]
<property name="ProblemUser" column="ProblemUser" type="Boolean" />
</class>
</hibernate-mapping>
I traced through the Persister.cs code to the point where the field values get bound to the SQL data parameters. When NullSafeSet is called for the NHibernate.Type.DateType type, the parameter is set to the entity's field value without truncating the time.
From DateType.cs
Code:
parm.DbType = DbType.Date;
parm.Value = value;
I would have expected some kind of "massaging" of the value to truncate the time portion (the inverse of what is done in DateTimeType.cs)
From DateTimeType.cs
Code:
DateTime dateValue = ( DateTime ) value;
parm.Value = new DateTime( dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second );
Am I completely offbase here in thinking that the date type should truncate the time portion?
Thanks