【发布时间】:2022-01-26 18:10:20
【问题描述】:
我的表 ReportData 有以下记录
| Agency | Year | Month | MonthCount |
|---|---|---|---|
| One | 2017 | Jan | 4 |
| One | 2017 | Feb | 6 |
| One | 2017 | Nov | 29 |
| One | 2017 | Dec | 38 |
| One | 2018 | Jan | 20 |
| One | 2019 | Feb | 18 |
| Two | 2017 | Jan | 24 |
| Two | 2017 | Feb | 66 |
| Three | 2017 | Nov | 9 |
| Four | 2017 | Dec | 8 |
| Four | 2018 | Jan | 22 |
| Four | 2019 | Feb | 48 |
如何转换成下表?请让我知道 Linq 声明。提前感谢您的帮助。
| Agency | Month | 2017 | 2018 | 2019 |
|---|---|---|---|---|
| One | Jan | 4 | 20 | 0 |
| One | Feb | 6 | 0 | 18 |
| One | Nov | 29 | 0 | 0 |
| One | Dec | 38 | 0 | 0 |
| Two | Jan | 24 | 0 | 0 |
| Two | Feb | 66 | 0 | 0 |
| Three | Nov | 9 | 0 | 0 |
| Four | Jan | 0 | 22 | 0 |
| Four | Feb | 0 | 0 | 48 |
| Four | Dec | 8 | 0 | 0 |
源类结构
public class ReportingData
{
public string AgencyName { get; set; }
public int Year { get; set; }
public string MonthNumnber { get; set; }
public string Month { get; set; }
public int MonthCount { get; set; }
}
【问题讨论】:
-
我尝试使用数据表进行操作,但现在确定如何使用 Linq。因此,如果有人知道如何编写 Linq 语句或为我指明方向,请提问 - 谢谢!
-
你能分享你的源类和目标类结构吗?
-
@SateeshPagolu 这里是我的源类 public class ReportingData { public string AgencyName { get;放; } 公共 int 年份 { 获取;放; } 公共字符串 MonthNumber { 获取;放; } 公共字符串月 { 获取;放; } 公共 int MonthCount { 获取;放; } }
-
@SateeshPagolu - 我已将源类添加到问题以便更好地阅读
-
你也可以添加你的目标类型定义吗?
标签: .net asp.net-mvc linq