Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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# 使用Lambda在列表中列出_C#_Wpf_Linq_Lambda - Fatal编程技术网

C# 使用Lambda在列表中列出

C# 使用Lambda在列表中列出,c#,wpf,linq,lambda,C#,Wpf,Linq,Lambda,我有两个表,我想合并生成一个报告 我使用此代码连接表 db.tblProcessorLists.GroupJoin( db.tbltransactions, a => a.UserID, b => b.UserID, (x, y) => new { Processo

我有两个表,我想合并生成一个报告

我使用此代码连接表

db.tblProcessorLists.GroupJoin(
                 db.tbltransactions,
                 a => a.UserID,
                 b => b.UserID,
                 (x, y) => new
                 {
                     Processor = x,
                     Data = y.ToList()
                 }
         )
         .Select(a => new Report
         {
             Processor = a.Processor,
             TotalTrans = a.Data
         }).ToList();
这就是输出

我想在我的报表类中插入数据

这可能吗?如何实现

编辑 我已经试过了,但不起作用

db.tblProcessorLists.GroupJoin(
                 db.tbltransactions,
                 a => a.UserID,
                 b => b.UserID,
                 (x, y) => new
                 {
                     Processor = x,
                     Data = y.ToList()
                 }
         )
         .Select(a => new Report
         {
             Processor = a.Processor,
             SummaryTransaction = a.Data.Select(x=>new Summaryreport{ month=x.month, year=x.year, total=x.totaltransaction})
         }).ToList();

虽然您没有具体说明,但我认为您需要将一个月的所有数据相加。因此,不是:

Processor Month   Value
    1    2018-1     2
    1    2018-1     3  => sum all 2018-1 values of processor 1: 2+3=5
    1    2018-2     4
    1    2018-2     5  => sum all 2018-2 values of processor 1: 4+5=9
    2    2018-1     1
    2    2018-1     2  => sum all 2018-1 values of processor 2: 1+2=3
您所要做的就是更改GroupJoin中的ResultSelector,以便它使用相同的[year,month]将所有数据分组。结果是今年和月份的所有值的[年、月、和]

请参见的重载之一


虽然您没有具体说明,但我认为您需要将一个月的所有数据相加。因此,不是:

Processor Month   Value
    1    2018-1     2
    1    2018-1     3  => sum all 2018-1 values of processor 1: 2+3=5
    1    2018-2     4
    1    2018-2     5  => sum all 2018-2 values of processor 1: 4+5=9
    2    2018-1     1
    2    2018-1     2  => sum all 2018-1 values of processor 2: 1+2=3
您所要做的就是更改GroupJoin中的ResultSelector,以便它使用相同的[year,month]将所有数据分组。结果是今年和月份的所有值的[年、月、和]

请参见的重载之一


@TDK我已经添加了我想添加的内容您可能会得到更多答案,用C#和LINQ标记您的问题而不是WPF(我在您的问题中没有看到任何WPF)。@TDK我已经添加了我想添加的内容您可能会得到更多答案,用C#和LINQ标记您的问题而不是WPF(我在您的问题中没有看到任何WPF)。