且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据表转换为IEnumerable时出错

更新时间:2023-02-14 10:55:49

您会收到此错误,因为 dtRepSummary.AsEnumerable()返回 IEnumerable< DataRow> ,但是您有返回类型为 IEnumerable< Landing> ,则可以使用

You are getting that error because dtRepSummary.AsEnumerable() returns IEnumerable<DataRow> but you have the return type as IEnumerable<Landing>, you can use Select to project your type like this:-

return dtRepSummary.AsEnumerable().Select(x => new Landing
                                        {
                                           Reportid = x.Field<int>("Reportid"), 
                                           Reportdate = x.Field<string>("Reportdate"),
                                           ..and so on
                                        };