我有一个很好的LINQ
声明,Oracle 不喜欢:
var result = from r in Context.Accounts
where Statuses.Contains(r.DEC_CD)
&& r.Deposit.Payments.Where(n => n.CreatedDate >= DateStart).Sum(n => n.Total - n.Fees) > 3000
select r;
不幸的是,.Where(...).Sum(...)
使用 Oracle EF 提供程序创建了无效的 SQL。
我试图改用 group 重写它:
var result = from g in Context.Payment
where g.CreatedDate >= DateStart
group g by g.Total - g.Fees into grp
where grp.Key >= 3000
select g;
上面的示例无法编译。
var result = from g in Context.Payment
where g.CreatedDate >= DateStart
group g by g.Total - g.Fees into grp
where grp.Key >= 3000
select new { g };
也不编译
var result = from g in Context.Payment
where g.CreatedDate >= DateStart
group g by g.Total - g.Fees into grp
where grp.Key >= 3000
select grp.SelectMany(n => n);
看起来它可以从 Intellisense 工作,但我收到一个错误The type arguments for method SelectMany cannot be inferred from the usage
我唯一能够选择的只是 grp,如果我选择它,我会得到Igrouping<decimal, Payment>' which has keys and multiple rows underneath. I just want the rows, hence the
.SelectMany`
知道如何弄平IEnumerable<Payment>
吗?