Just for reference sake...
Here are the three expressions that I created (vb.net).
Imports SD.LLBLGen.Pro.ORMSupportClasses
The first one allows you to specify any function with a single parameter. This is just a cut of your code Frans at the thread mentioned above in vb.net.
<Serializable()> _
Public Class FunctionExpression
Inherits Expression
Private _FunctionToApply As String = String.Empty
Public Sub New(ByVal Field As IEntityField, ByVal FunctionToApply As String)
MyBase.New(Field)
_FunctionToApply = FunctionToApply
End Sub
Public Sub New(ByVal Field As IEntityField2, ByVal FunctionToApply As String)
MyBase.New(Field)
_FunctionToApply = FunctionToApply
End Sub
Public Shadows Function ToQueryText(ByRef uniqueMarker As Integer, ByVal inHavingClause As Boolean) As String
If _FunctionToApply.Length > 0 Then
Return String.Format("{0}({1})", _FunctionToApply, MyBase.ToQueryText(uniqueMarker, inHavingClause))
Else
Return MyBase.ToQueryText(uniqueMarker, inHavingClause)
End If
End Function
Public Property FunctionToApply() As String
Get
Return _FunctionToApply
End Get
Set(ByVal Value As String)
_FunctionToApply = Value
End Set
End Property
End Class
The second one returns whole date parts without the time. Great except that it returns as a varchar(11) so it is not really sortable by date - better when sorting is not necessary.
<Serializable()> _
Public Class FunctionExpressionToShortDate
Inherits Expression
Public Sub New(ByVal Field As IEntityField)
MyBase.New(Field)
End Sub
Public Sub New(ByVal Field As IEntityField2)
MyBase.New(Field)
End Sub
Public Shadows Function ToQueryText(ByRef uniqueMarker As Integer, ByVal inHavingClause As Boolean) As String
Return String.Format("{0}(varchar(11),{1},101)", "Convert", MyBase.ToQueryText(uniqueMarker, inHavingClause))
End Function
End Class
The third one converts to the varchar short date, then back to a datetime to allow for sorting based on date. Less efficient, but easy to sort.
<Serializable()> _
Public Class FunctionExpressionToShortDateSortable
Inherits Expression
Public Sub New(ByVal Field As IEntityField)
MyBase.New(Field)
End Sub
Public Sub New(ByVal Field As IEntityField2)
MyBase.New(Field)
End Sub
Public Shadows Function ToQueryText(ByRef uniqueMarker As Integer, ByVal inHavingClause As Boolean) As String
Return String.Format("{0}(datetime,{0}(varchar(11),{1},101))", "Convert", MyBase.ToQueryText(uniqueMarker, inHavingClause))
End Function
End Class
Thanks again for all the help on this. I can't really think of ANYTHING I can't do with LLBL anymore. !
Hal