Hello Guys,
I have read everything that is required to solve this but I still cannot find a solution, so sorry.
I want to create a typed list from a Typed View and an Entity Collection, which is illustrated in the following SQL query:
Select c.strCustomerId, c.strCompanyName,
(Select SUM(ca.decTrxAmount - ca.decAmountAllocated) As Amount
From vwCustomerAllocation ca
Where ca.blnAllocated = 0 And ca.strTrxAllocation = 'Debit' And ca.strCustomerId = c.strCustomerId
And ca.dtmTrxDate Between '2010/06/15 0:00:00' And '2010/07/15 23:59:59') As ZeroToThirty
From Customer c
There are other fields I want to create, but, if we can achieve this first I think I can continue with the rest.
I have started like this:
Dim fields As New ResultsetFields(3)
fields.DefineField(CustomerFields.StrCustomerId, 0)
fields.DefineField(CustomerFields.StrCompanyName, 1)
Dim dtGroupBy As New GroupByCollection(fields(0))
Dim ex As New Expression(CustomerAllocationFields.DecTrxAmount, ExOp.Sub, CustomerAllocationFields.DecAmountAllocated)
Dim ef As New EntityField("MainField", ex, AggregateFunction.Sum)
'Create field for 0 - 30
fields.DefineField(New EntityField("0-30", New ScalarQueryExpression(ef, CustomerAgingFilter(0, 30), CustomerRelations)), 2)
Dim filter As IPredicateExpression = New PredicateExpression
Dim results As New DataTable()
Dim dao As New TypedListDAO()
dao.GetMultiAsDataTable(fields, results, 0, Nothing, filter, Nothing, True, dtGroupBy, Nothing, 0, 0)
Private Function CustomerAgingFilter(ByVal fromDays As Integer, ByVal toDays As Integer) As IPredicateExpression
Dim fPR As IPredicateExpression = New PredicateExpression
Dim dateFrom As Date = Date.Today.AddDays(toDays * -1)
Dim dateto As Date = Date.Today.AddDays(fromDays * -1)
fPR.Add(CustomerAllocationFields.StrCustomerId = CustomerFields.StrCustomerId)
fPR.AddWithAnd(CustomerAllocationFields.BlnAllocated = False)
fPR.AddWithAnd(CustomerAllocationFields.StrTrxAllocation = "Debit")
fPR.AddWithAnd(New FieldBetweenPredicate(CustomerAllocationFields.DtmTrxDate, New Date(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0), New Date(dateto.Year, dateto.Month, dateto.Day, 23, 59, 59)))
Return fPR
End Function
Private Function CustomerRelations() As IRelationCollection
Dim r As IRelationCollection = New RelationCollection()
r.Add(New EntityRelation(CustomerFields.StrCustomerId, CustomerAllocationFields.StrCustomerId, RelationType.OneToMany))
Return r
End Function
But it isn't working. What am I doing wrong? I keep getting the total for ALL customers in every row.
Customer = CustomerEntity
CustomerAllocation = TypeView