从存储过程中,我得到的数据的列名如 Last year
和 01
、02
、03
... 在第一种情况下,列名由两个单词组成,在其他情况下,列名是带前导零的数字。我知道这个存储过程的设计者做了一些愚蠢的事情,但是我不能改变存储过程。我的目标是按一些列对数据进行分组,然后按这些奇怪的列名对其进行求和,但 VS2017 不喜欢它。我做了以下操作:
var list = (from r in dataFromSP
group r by new { r.TicketTypeName, r.PaymentMonth } into grp
select new
{
grp.Key.TicketTypeName,
grp.Key.PaymentMonth,
LastYear = grp.Sum(t => (decimal?)t.Last year),
M01 = grp.Sum(t => (decimal?)t.01),
M02 = grp.Sum(t => (decimal?)t.02),
M03 = grp.Sum(t => (decimal?)t.03),
M04 = grp.Sum(t => (decimal?)t.04),
M05 = grp.Sum(t => (decimal?)t.05),
M06 = grp.Sum(t => (decimal?)t.06),
M07 = grp.Sum(t => (decimal?)t.07),
M08 = grp.Sum(t => (decimal?)t.08),
M09 = grp.Sum(t => (decimal?)t.09),
M10 = grp.Sum(t => (decimal?)t.10),
M11 = grp.Sum(t => (decimal?)t.11),
M12 = grp.Sum(t => (decimal?)t.12)
}).ToList<dynamic>();
我不知道如何使用 LINQ 处理这些奇怪的列名。我试过 [],
LastYear = grp.Sum(t => (decimal?)t.[Last year]),
M01 = grp.Sum(t => (decimal?)t.[01]),
和“”,
LastYear = grp.Sum(t => (decimal?)t."Last year"),
M01 = grp.Sum(t => (decimal?)t."01"),
但没有运气。是否可以在 LINQ 中使用这些奇怪的列名,有什么办法可以解决这种奇怪的情况吗?
我是一名优秀的程序员,十分优秀!