Hi,
I am very new to LLBLGEN and am trying to work out a query based on two related entities:
Vouchers and VoucherSales
A Voucher defines a field named VoucherSaleLimit, which is an integer field indicating the maximum number of that voucher which can be sold.
I need a query that returns only Vouchers that have a quantity sold that is less than the VoucherSaleLimit...With quantity sold being the COUNT of related VoucherSale records.
The SQL would look something like:
SELECT v.VoucherId, v.VoucherSaleLimit, COUNT(vs.VoucherId) AS Sales
FROM Voucher v
LEFT OUTER JOIN VoucherSale vs ON vs.VoucherId = v.VoucherId
GROUP BY
v.VoucherId, v.VoucherSaleLimit
HAVING COUNT(vs.VoucherId) < v.VoucherSaleLimit
This is what I have so far - The "?????" is what I need help with.
public static EntityCollection LoadVouchers()
{
EntityCollection vouchers = new EntityCollection(new VoucherEntityFactory());
DataAccessAdapter adapter = new DataAccessAdapter();
//add prefetches
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.VoucherEntity);
prefetchPath.Add(VoucherEntity.PrefetchPathVoucherSale);
//add filters
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(??????);
//add sorter
ISortExpression sorter = new SortExpression();
sorter.Add(VoucherFields.StartDate | SortOperator.Ascending);
sorter.Add(VoucherFields.VoucherTitle | SortOperator.Ascending);
//get collection and sort
adapter.FetchEntityCollection(vouchers, filter, 0, sorter, prefetchPath);
return vouchers;
}
Can anyone tell me firstly, if this is possible, and secondly, how..??
Cheers,
Jack