public ActionResult Index(int? p, FormCollection formcollection)
{
var Query1 = from CompanyInfo in ef.Company_Info orderby CompanyInfo.Company_ID descending select new { AutoID=CompanyInfo.AutoID, CompanyAddress=CompanyInfo.CompanyAddress, CompanyName=CompanyInfo.CompanyName, CompanyTel=CompanyInfo.CompanyTel };
PagedList<Company_Info> QueryList = Query1.ToPagedList(p ?? 1, 20);
return View(QueryList);
}
一直报错:
错误 1 无法将类型“System.Linq.IQueryable<AnonymousType#1>”隐式转换为“System.Linq.IOrderedQueryable<PingL.Models.Company_Info>”。存在一个显式转换(是否缺少强制转换?) E:\pingl\PingL\PingL\Controllers\HomeController.cs 28 245 PingL
匿名类型无法直接转换为真实类型,
匿名类应该不能直接转换成Company_Info的集合吧。
IList queryList = Query1.ToList(p ?? 1, 20);
PagedList<Company_Info> QueryList = new PagedList<Company_Info>();
foreach(dynamic entity in queryList)
{
var info= new Company_Info { XX = entity.XX,YY=entity.YY};
QueryList.Add(info);
}
这样转来转去性能会不会受影响了
@wydycg: 肯定会有影响的,但是相对反射肯定好点