I am having trouble expressing a query in the LLBLGen Predicate System.
I am able to express the same query in Linq (Linqdatasource coupled with LLBLGen LinqMetaData), however, the LinqDataSource coupled with LLBLGen meta data does not do updates...
Can you please help me translate this query to LLBLGen filter mechanism?
The Linq query is:
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
LinqMetaData metaData = new LinqMetaData();
var q = from c in metaData.FeeRecord
where !(c.ParentRecordId.HasValue)
&& (
(c.StatusId == 7)
||
(c.StatusId == 10 && c.AmountToBeTraded == c.ChildrenRecords.Where(c1 => c1.StatusId == 7).Sum(c1 => c1.AmountToBeTraded))
)
orderby c.Plan.Name
select c;
e.Result = q;
}
In the above query, if statusid is 10, then we want to make sure that the sum of all the children's amount whose status id is 7 should equate to the parent's amount.
Here is what I have so far:
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(FeeRecordEntity.Relations.FeeRecordEntityUsingParentRecordId, "ChildrenFeeRecords");
relationsToUse.ObeyWeakRelations = true;
PredicateExpression filter = new PredicateExpression();
filter.Add(
(FeeRecordFields.StatusId == new List<int>() { 7 })
|
(FeeRecordFields.StatusId == new List<int>() { 10 }
& FeeRecordFields.StatusId.SetObjectAlias("ChildrenFeeRecords") == 7
& FeeRecordFields.AmountToBeTraded == FeeRecordFields.AmountToBeTraded.SetObjectAlias("ChildrenFeeRecords").SetAggregateFunction(AggregateFunction.Sum))
);
filter.Add(FeeRecordFields.ParentRecordId == DBNull.Value);
However, the above filter query does not work. The entire bit about children's sum being equal to parent's amount is being ignored.
Using LLBLGen version 2.6.9.616, ASP.Net version 3.5.