如何在添加特定条件的项目后对某些元素进行分组,然后在 c# 中执行 linq 到 sql

阿布巴卡尔·特拉奥雷

这似乎是一个愚蠢的问题,但我真的需要帮助。我不经常发布问题,但这次我真的很有帮助。

我需要一个对多列进行分组的 linq to sql 查询。但不仅如此,其中一列具有特定的也需要基于certain condition.

我的查询是这个。

using (var donnée = new ClassDonnéeDataContext(mycontrng))
        {
            var don = from d in donnée.Reservations
                      where (d.Date_Livraison.Value.Date == startDate.Value.Date) && d.Sortie_Cuisine != "Oui" && d.Livraison != "Annulée" && (d.Reserv_Boutique == "Non" || d.Reserv_Boutique == null)
                      group d by new
                      {
                          Gateau = d.Gateau,
                          Heure = d.Heure_Livraison,
                          Nb_Part = d.Part,
                      } into grs
                      select new
                      {
                          Gateau = grs.Key.Gateau,
                          Heure = grs.Key.Heure,
                          Nombre = grs.Sum(x => x.Nombre),
                          Nb_Part = grs.Key.Nb_Part,
                      };

            var order = from ord in don
                        orderby ord.Heure ascending
                        select ord;

            dgv.DataSource = order;
        } 

我正在寻找的结果是让列"Heure_Livraison"按特定标准分组。

查询结果如下。

Gateau:                               Heure:                 Nombre:                  Nb_Part:

Foret Noire                           10                     2                        6
Ganache                               10                     2                        6
Foret Noire                           11                     2                        6
Ganache                               11                     2                        6
Ganache                               12                     1                        6

现在我想添加所有同名的蛋糕,相同的 Nb_PartBetween 10-12.所以结果会喜欢

Gateau:                               Heure:                 Nombre:                  Nb_Part:

Foret Noire                           10                     4                        6
Ganache                               10                     5                        6

如果有人对这个问题有建议,请给我!!!``

阿布巴卡尔·特拉奥雷

我终于通过创建一个单独的列并指定要存储在该列中的数据来解决问题,以便在查询后我只需要选择该列。

谢谢你的评论!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章