Using LLBLGen Pro v 2.5 Final in a VS 2008 project.
I've been going around and around with this and I've felt like I was close to the solution a couple of times, but I can't quite break through. Can anyone give me a push in the right direction?
I have created a Manager Class for some business logic for each Entity Class. For example, my BranchEntity has a BranchEntityManager.
Public Class BranchEntityManager
Inherits ManagerBase
Protected ReadOnly Property DefaultSort() As SortExpression
Get
Dim Sort As New SortExpression()
Sort.Add(New SortClause(BranchFields.BranchCode, Nothing, SortOperator.Descending))
Sort.Add(New SortClause(BranchFields.BranchName, Nothing, SortOperator.Ascending))
Return Sort
End Get
End Property
Protected ReadOnly Property MaxItemsToReturn() As Integer
Get
Return 0
End Get
End Property
Protected ReadOnly Property CompanyPrefetch() As PrefetchPath2
Get
Dim PrefetchPath As New PrefetchPath2(CType(EntityType.BranchEntity, Integer))
PrefetchPath.Add(BranchEntity.PrefetchPathCompany)
Return PrefetchPath
End Get
End Property
Public Function GetList() As EntityCollection(Of BranchEntity)
Return GetList(Me.DefaultSort)
End Function
Public Function GetList(ByVal sort As SortExpression) As EntityCollection(Of BranchEntity)
Dim BranchList As New EntityCollection(Of BranchEntity)
Dim Bucket As New RelationPredicateBucket
Using MyAdapter As DataAccessAdapter = MyBase.GetAdapter()
MyAdapter.FetchEntityCollection(BranchList, Bucket, Me.MaxItemsToReturn, sort, Me.CompanyPrefetch)
End Using
Return BranchList
End Function
End Class
As you can see, I have overloaded by GetList method to use a default sort or to accept a sort expression provided by the consumer.
Next, I wanted to create a class within the BranchManager class which is used to limit the sort fields to only BranchEntityFields.
Public Class SortOrder
Private _Sort As SortExpression
Public ReadOnly Property Sort() As SortExpression
Get
If _Sort Is Nothing Then
_Sort = New SortExpression
End If
Return _Sort
End Get
End Property
Public Sub AddSortItem(ByVal fieldIndex As BranchFieldIndex, ByVal direction As SortDirection)
If _Sort Is Nothing Then
_Sort = New SortExpression
End If
Dim Field As EntityField2 = EntityFieldFactory.Create(CType(fieldIndex, BranchFieldIndex))
Sort.Add(New SortClause(Field, direction))
End Sub
End Class
It will be used like so:
Dim BranchManager As New BranchEntityManager
Dim SortOrder As New BranchManager.SortOrder
SortOrder.AddSortItem(BranchFieldIndex.City, SortDirection.Ascending)
SortOrder.AddSortItem(BranchFieldIndex.StateCode, SortDirection.Ascending)
Dim BranchList As EntityCollection(Of BranchEntity) = BranchManager.GetList(SortOrder.Sort)
The problem I run into is that in the SortOrder class, when I do a Sort.Add in the AddSortItem method, I get an error because Sort.Add expects an IEntityField and not the IEntityField2 that is created by the EntityFieldFactory.Create method.
I'm sure I'm just overlooking something obvious
or maybe I'm headed down the wrong path
. A little direction or a big correction. Either would be appreciated.
...Jim...