无法将类型'System.Collections.Generic.List <anonymoustype#1>'隐式转换为'System.Collections.Generic.List <system.datetime>'

时间:2016-08-23 07:39:41

标签: c# linq

List<DateTime> listdate = new List<DateTime>();

 var InList = (from b in mstdocstats
                            join a in mstdocs on a.docid = b.docid
                            where a.vtype = 'table'
                            && a.DCREA.Month == "06" && a.DCREA.Year == "2016"
                            select a.docid).ToList();



 var listreaddate = (from b in mstdocstats
                    join a in mstdocs on a.docid = b.docid
                    where InList.Contains(a.docid) && a.vtaid = '2'
              && a.vtype = 'read'
                             select new
                              {
                                   Read_DATE = ((from mstdoc in mstdocs
                                                   where
                                                   mstdoc.docid == a.docid &&
                                                     mstdoc.vtype == "read"
                                                   select new
                                                   {
                                                        mstdoc.DCREA
                                                  }).First().DCREA)
                                }).ToList();

但是我收到一条报告C#无法转换列表的错误:

  

“错误:无法隐式转换类型

'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<System.DateTime>'

请指导我正确的解决方案如何才能实现这一目标,谢谢......

1 个答案:

答案 0 :(得分:0)

以下行创建一个新的匿名对象,其中包含一个属性为datetime:

                         select new
                          {
                               Read_DATE = ((from mstdoc in mstdocs
                                               where
                                               mstdoc.docid == a.docid &&
                                                 mstdoc.vtype == "read"
                                               select new
                                               {
                                                    mstdoc.DCREA
                                              }).First().DCREA)
                            }

尝试此操作以获取日期时间列表:

                         select  ((from mstdoc in mstdocs
                                               where
                                               mstdoc.docid == a.docid &&
                                                 mstdoc.vtype == "read"
                                               select new
                                               {
                                                    mstdoc.DCREA
                                              }).First().DCREA)
相关问题