asp.net mvc ToList 转换为非委托类型错误

来源:互联网 发布:淘宝如何找货源 编辑:程序博客网 时间:2024/06/09 16:30

提示 错误 1 无法将方法组“ToList”转换为非委托类型“System.Collections.Generic.List

private List <MyDate> GetSameData(string user, int year, int month, string reftable)        {            cjd = new CJArchivesDataContext();            var query = from  l in cjd.LocalNews                          where l.Folder.aspnet_Info.aspnet_User.UserName == user                                && Convert.ToDateTime(l.refDate.ToString()).Year == year                                && Convert.ToDateTime(l.refDate.ToString()).Month==month                                && l.refTable == reftable                          select new                          {                              TableName = l.refTable,                              Numb = l.refNumb                          };            return query.ToList <MyDate>;        }    public class MyDate    {        public string TableName {get;set;}        public string Numb  {get;set;}    }

应该写作
修改为:

select new MyDate                           {                               TableName = l.refTable,                               Numb = l.refNumb                           }; return query.ToList <MyDate>();

原文地址:http://bbs.csdn.net/topics/310138507