Cannot implicitly convert type 'System.Collections.Generic.List in C#

前端 未结 2 890
孤城傲影
孤城傲影 2021-01-22 01:48

Hi I\'m new to programming, could you please help me with this one:

I\'am getting an error in \"To.List()\" Error 1 Cannot implicitly convert type \'System.Co

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 02:46

    You should just change this

    select new { d.Key.month, d.Key.year, count = d.Count() }
    

    to this

    select new IncByYrMonthModel { Month = d.Key.month, Year = d.Key.year, Total = d.Count() }
    

    The problem in the first case is that you have a sequence of object of an anonymous type, which you try to convert them to a list of IncByYrMonthModel, which is impossible.

提交回复
热议问题