我正在尝试使用一些参数查询表的最大值(长),尝试使用Punch Framework。
这是原始的LINQ查询:
Table.Where(x=>x.GroupId == 1).Max(x=>x.LongValue)
我想将此LINQ查询转换为使用Cocktail Repository:
(await UnitOfWork.GetRepository<Table>()
.FindAsync(selector => selector.Select(x => x.LongValue), predicate => predicate.GroupId.Equals(1),))
.FirstOrDefault();
这适用于选择组的第一个LongValue,但是如何更改查询以获得表的最大结果?
答案 0 :(得分:2)
DevForce正确使用AsScalarAsync方法来处理标量查询的异步执行。 Punch并没有直接实现这一点,但您可以扩展您的存储库类来提供此功能。它看起来类似于基类SELECT DESCRIPTION,
(SELECT SUM(USAGE) FROM InvoiceDetail
WHERE UNIT = @UNIT, InvoiceDate BETWEEN :firstWeekBegin AND :firstWeekEnd as Week1Usage),
(SELECT SUM(USAGE) FROM InvoiceDetail
WHERE UNIT = @UNIT, InvoiceDate BETWEEN :secondWeekBegin AND :secondWeekEnd as Week2Usage),
SELECT PRICE FROM InvoiceDetail
WHERE UNIT = @UNIT, InvoiceDate = firstWeekBegin as Week1Price),
(SELECT PRICE FROM InvoiceDetail
WHERE UNIT = @UNIT, InvoiceDate = secondWeekBegin as Week2Price),
FROM InvoiceDetail
WHERE UNIT = @UNIT, InvoiceDate BETWEEN @BEGDATE AND @ENDATE ORDER BY PRODUCTS
类如何实现CountAsync。像这样:
Repository<T>
DevForce对Max有几个重载,所以请查看文档以了解哪个最适合您。