1

我有一个很好的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>吗?

4

3 回答 3

1

你可能只是想要这个

var result = from g in Context.Payment
    where g.CreatedDate >= DateStart
          && (g.Total - g.Fees) >= 3000
    select g;

对?总费用为 gte 3000 和日期标准的所有付款。看来该组不是有意或不需要的。

于 2013-03-28T17:46:24.247 回答
1

您必须添加一个 from 语句才能重新选择该组:

var result = from g in Context.Payment
        where g.CreatedDate >= DateStart
        group g by g.Total - g.Fees into grp
        where grp.Key >= 3000
        from i in grp
        select i;
于 2013-04-01T18:00:43.910 回答
0
var result = 
        from p in Context.Payment
        where p.CreatedDate >= DateStart
        group p by p.Total - p.Fees into g
        where g.Key >= 3000
        select g; // select group here

或者不分组更好:

var result = 
        from p in Context.Payment
        where p.CreatedDate >= DateStart &&
              (p.Total - p.Fees) >= 3000
        select p; 
于 2013-03-28T17:48:20.943 回答