首页 > 代码库 > linq 加orderby后报错
linq 加orderby后报错
今天下午做一高效分页,
var spdmList = from d in data
select d.spdm;
var resdata = http://www.mamicode.com/from z in db.z_tz
where spdmList.Contains(z.spdm)
select z;
在resdata中加一个orderby 便会报错如:
var resdata = http://www.mamicode.com/from z in db.z_tz
orderby z.id
where spdmList.Contains(z.spdm)
select z
报错详细为:Unknown column ‘Extent1.spdm‘ in ‘where clause‘
只能tolist后再orderby
问题解决:
var spdmList = from d in data
select d.spdm;
var resdata = http://www.mamicode.com/from z in db.z_tz
where spdmList.Contains(z.spdm)
select z;
改为
var spdmList = (from d in data
select d.spdm).ToList() ;
var resdata = http://www.mamicode.com/from z in db.z_tz
orderby z.id
where spdmList.Contains(z.spdm)
select z ;
先spdmList 变为内存数据就OK