Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#LINQ Select JOIN GroupBy不工作_C#_Linq_Entity Framework Core - Fatal编程技术网

C#LINQ Select JOIN GroupBy不工作

C#LINQ Select JOIN GroupBy不工作,c#,linq,entity-framework-core,C#,Linq,Entity Framework Core,我正在使用entityFramework内核,得到了一个LINQ查询select、inner join、where和结果。我需要添加GroupBy,这是一个错误。我跟随了一些帖子,模仿了他们的代码,但我被绊倒了 我对翻译成LINQ有意见 这是我的linq,它在没有GroupBy的情况下工作 var result = this.myDbContent.Table1 .Join(this.Table2, table1 =>

我正在使用entityFramework内核,得到了一个LINQ查询select、inner join、where和结果。我需要添加GroupBy,这是一个错误。我跟随了一些帖子,模仿了他们的代码,但我被绊倒了

我对翻译成LINQ有意见

这是我的linq,它在没有GroupBy的情况下工作

var result = this.myDbContent.Table1
               .Join(this.Table2,
                     table1 => table1.myId,
                     table2 => table2.myId,
                     (table1 ,table2) => {table1 ,table2}
               )
               .Join(this.Table3,
                     table1_table2 => table1_table2.table1.myId,
                     table3 => table3.myId,
                     (table1_table2 ,table3) => {tabtable1_table2 e1 ,table3}
               )
               .Where(
                 s => s.table1_table2.table1.myId == 1 &&
                 s.table1_table2.table2.isCompleted == true
               )
               .Select(s => new
               {
                  MyID = s.table1_table2.table1.myId,
                  MyDate = s.table1_table2.Table2.CompletedDate
               });
此查询工作并返回记录

在下面的文章中,我根据另一篇文章添加了GroupBy

var result = this.myDbContent.Table1
               .Join(this.Table2,
                     table1 => table1.myId,
                     table2 => table2.myId,
                     (table1 ,table2) => {table1 ,table2}
               )
               .Join(this.Table3,
                     table1_table2 => table1_table2.table1.myId,
                     table3 => table3.myId,
                     (table1_table2 ,table3) => {tabtable1_table2 e1 ,table3}
               )
               .Where(
                 s => s.table1_table2.table1.myId == 1 &&
                 s.table1_table2.table2.isCompleted == true
               )
               .GroupBy(s => new
                 {
                    MyID = s.table1_table2.table1.myId,
                    MyDate = s.table1_table2.Table2.CompletedDate
                 }
               )
               .Select(s => new
               {
                  MyID = s.Key.myId,
                  MyDate = s.Key.CompletedDate,
                  Count = s.Count()
               });
当我使用GroupBy运行此查询时,我得到一个“SYstem.InvalidOperationException”

我正在尝试将以下SELECT GROUPBY添加到工作查询中

Select Count(*) AS Counts, MyID, MYDATE
FROM ( the working query above )
GROUP BY MyID, MYDATE

谢谢

分组前将其转换为列表或可枚举

var result = this.myDbContent.Table1
               .Join(this.Table2,
                     table1 => table1.myId,
                     table2 => table2.myId,
                     (table1 ,table2) => {table1 ,table2}
               )
               .Join(this.Table3,
                     table1_table2 => table1_table2.table1.myId,
                     table3 => table3.myId,
                     (table1_table2 ,table3) => {tabtable1_table2 e1 ,table3}
               )
               .Where(
                 s => s.table1_table2.table1.myId == 1 &&
                 s.table1_table2.table2.isCompleted == true
               ).AsEnumerable()
               .GroupBy(s => new
                 {
                    MyID = s.table1_table2.table1.myId,
                    MyDate = s.table1_table2.Table2.CompletedDate
                 }
               )
               .Select(s => new
               {
                  MyID = s.Key.table1_table2.table1.myId,
                  MyDate = s.Key.table1_table2.Table2.CompletedDate,
                  Count = s.Count()
               });

您的组键只有
MyID
MyDate
字段-对已联接表的引用已消失,因此请在选择中引用这些字段:

.Select(s => new
           {
              MyID = s.Key.MyID,
              MyDate = s.Key.MyDate,
              Count = s.Count()
           }

请发送完整的错误信息