错误6无法将类型“System.Linq.IQueryable AnonymousType#1 ;”隐式转换为“System.Linq.IQueryable<OfficeChannel.DAL.Of
public IQueryableGetMessage(OfficeToolList offID) { DALDataContext MyCon = DAL_Connection.Connection; var linq = from i in MyCon.OfficeToolList where i.ToolID == offID.ToolID select new { softID=i.ToolID, softTypeID=i.ToolClassID, softUrl=i.FileURL, softDownUrl=i.DownloadPageURL, softName=i.ToolName, softEdition=i.Vision, softSize=i.FileLenght, softFormat=i.Type, softDownTime=(from ii in MyCon.DownloadLog where ii.ToolID==offID.ToolID select ii).Count(), softDataTime=i.PublishDate }; foreach (var item in linq) { OfficeChannel.Model.Tips_M_ToolList model = new OfficeChannel.Model.Tips_M_ToolList(); model.ToolName = item.softName; model.Vision = item.softEdition; model.FileLenght = Convert.ToInt32(item.softSize); model.Type = item.softFormat; model.PublishDate = Convert.ToString(item.softDataTime); model.count = item.softDownTime; model.ToolID = item.softID; model.ToolClassID = new Guid(Convert.ToString(item.softTypeID)); model.FileURL = item.softUrl; model.DownloadPageURL = item.softDownUrl; } return linq;//错误在这 转化成什么类型呢? }
------解决方法--------------------------------------------------------
你的函数定义的是OfficeToolList类型数据,而你返回是的OfficeChannel.DAL,当然报错
你可以把函数定义改成IQueryable <OfficeChannel.DAL>
------解决方法--------------------------------------------------------
这里的linq是匿名类型了,也就是IQueryable <AnonymousType#1>
自己先写个class或struct来存select出的数据,如命名为Message1
然后select new Message1{...}
第一行改成
public IQueryable <Message1> GetMessage(OfficeToolList offID)
------解决方法--------------------------------------------------------
还是你要返回model,而不是linq,但foreach了好像又不是