【问题标题】:How to lambda the group by data on a LINQ to Sql results?如何通过 LINQ to Sql 结果上的数据对分组进行 lambda?
【发布时间】:2010-10-01 06:58:28
【问题描述】:
  1. 我是这样从数据库中获取数据的。

     Dim query = From t1 In TBL1 _
                 Join t2 In TBL2 On t1.ID Equals t2.ID _
                 Join t3 In TBL3 On t1.ID Equals t3.ID _
                 Group Join t4 In t1 _
                       On t1.ID Equals t4.ID _
                       Into t4_Grp = Group _
                 Select t1, t2, t3, t4_Grp
    
  2. 当用户执行搜索时,我可以像这样过滤查询结果。

    query = query.Where(Function(o) o.t1.ID = lngID)
    
  3. 以上一切正常。直到我想 lambda t4_Grp。我不知道如何在 t4_Grp 上做一个 lambda 表达式?

【问题讨论】:

  • 您能否澄清您的问题,“执行 lambda 表达式”或“lambda the t4_Grp”是什么意思?您是否尝试进行额外的过滤,但在表 t4 而不是 t1 上?
  • 是的,我正在尝试进行额外的过滤;在 t4_Grp 上。

标签: linq-to-sql lambda group-by


【解决方案1】:

我过去曾用它来做一些权力分组。

private void ProducePivotAnalytic <T, K>(IEnumerable<T> colletion, Func<T, K> pivot)
{
    var grouped =
        from n in colletion
            group n by pivot(n) into g
            select new { theKey = g.Key, theValue = g };
    // do some stuff with your grouped collection.
}


ProducePivotAnalytic<List<DateTime>, DayOfWeek>(
        myDates,
            (x) => (x.DayOfWeek) );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多