I'm having a problem where a DateTime field bound to a "virtual" column isn't working properly. The virtual column is created using GetLocalBindingProperties and is included in the query. Here's the query:
Code:
Public Function GetProspect(ByVal ProspectID As Integer) As BusinessObjects.Prospect Implements IDataAccess.GetProspect
Dim p As New BusinessObjects.ProspectQuery("p")
Dim a As New BusinessObjects.AppointmentQuery("a")
p.Select(p, a.StartDate.As("FollowUpDate"))
p.LeftJoin(a).On(p.FollowUpAppointmentID = a.AppointmentID)
p.Where(p.ProspectID.Equal(ProspectID))
Dim Prospect As New BusinessObjects.Prospect
Prospect.Load(p)
Return Prospect
End Function And my code in my custom Prospect entity:
Code:
Protected Overloads Overrides Function GetLocalBindingProperties() As List(Of EntitySpaces.Core.esPropertyDescriptor)
Dim props As New List(Of EntitySpaces.Core.esPropertyDescriptor)
props.Add(New EntitySpaces.Core.esPropertyDescriptor(Me, "FollowUpDate", GetType(DateTime)))
Return props
End Function
Public Property FollowUpDate() As Nullable(Of DateTime)
Get
If Me.GetColumn("FollowUpDate") Is System.DBNull.Value Then
Return Nothing
Else
Return CType(Me.GetColumn("FollowUpDate"), DateTime)
End If
End Get
Set(ByVal value As Nullable(Of DateTime))
Me.SetColumn("FollowUpDate", New Nullable(Of DateTime)(CDate(value)))
End Set
End PropertyI set the binding up in design time and the weird part is the FollowUpDate field is returned and bound properly when the form is loaded. If I change the value on the form (it's using DevExpress' DateEdit control), the property in my custom entity is updated perfectly fine. When I called BindingSource.EndEdit right before I call Prospect.Save, the entity's data is reverted back to what it was when it was read from the database and my change is gone.
I've researched the issue on the web and found references to issues binding to Nullable types when the binding is looking for a strict DateTime, not a DateTime?. The recommended approach of ensuring a Format is specified for the binding didn't work for me.