读书人

DLinq 进行 Skip().Take() 出现错误

发布时间: 2012-03-17 19:06:28 作者: rapoo

DLinq 进行 Skip().Take() 出现异常
最近,自己在研究Linq To Sql,当我进行关联查询全部数据时,能够把全部数据库查询出来,由于GridView需要进行分页,我想利用Linq To Sql 自带的Skip Take 方法,进行获取指定的数据。可执行后出现异常,源代码如下:

C# code
/// <summary>        /// 获取流动人口租住信息        /// </summary>        /// <param name="queryOption">查询选择信息</param>        /// <param name="pageindex">当前页的索引编号</param>        /// <param name="pagesize">页面的数据条数</param>        /// <returns>IEnumerable类型</returns>        public IEnumerable<ListUtility.FloatingPopulationDefault> FloatingPopulationInfo(FloatingQueryOption queryOption,int pageindex,int pagesize)        {            var q = (from p1 in _floatingLeaseInfo                    join p2 in _floatinginfo                    on p1.Idnumber equals p2.Idnumber                    join p3 in _lessorInfo                    on p1.Lessor equals p3.Code                    join p4 in _district                    on p3.District equals p4.Code                    join p5 in _subdistrict                    on p3.SubDistrict equals p5.Code                    where                    p1.Idnumber.Contains(queryOption.FloatingIdnumber) &&                    p2.Name.Contains(queryOption.FloatingName) &&                    p2.NamePY.Contains(queryOption.FloatingNamePY)                    select new ListUtility.FloatingPopulationDefault                    {                        FloatingName = p2.Name,                        FloatingNamePY = p2.NamePY,                        FloatingIdnumber = p2.Idnumber,                        Age = p2.Age,                        LessorID = p1.Lessor,                        LessorName = p3.Name,                        NativePlace = p2.NativePlace,                        InDate = p1.InDate,                        OutDate = p1.LeftDate,                        Sex = p2.Sex,                        Address = p4.Name + p5.Name + p3.DoorPlate + "号" + p1.RoomId + "房间"                    }).Skip(pageindex * pagesize).Take(pagesize);            return q.ToList<ListUtility.FloatingPopulationDefault>();         }

系统运行,出现的错误提示信息如下: 
--------------------------------------------

This provider supports Skip() only over ordered queries returning entities or projections that contain all identity columns, where the query is a single-table (non-join) query, or is a Distinct, Except, Intersect, or Union (not Concat) operation.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NotSupportedException: This provider supports Skip() only over ordered queries returning entities or projections that contain all identity columns, where the query is a single-table (non-join) query, or is a Distinct, Except, Intersect, or Union (not Concat) operation.

源错误:


行 167:
行 168:
行 169: return q.ToList<ListUtility.FloatingPopulationDefault>();
行 170:
行 171:


源文件: D:\MyTeam\QueryUtility\FloatingPopulationQuery.cs 行: 169

[解决办法]
我个人认为:
var query=
from a in db.a
select new {a};
return query.skip(PageIndex * PageSize).Take(PageSize);
[解决办法]
前几天刚做了.我是这样实现的
C# code
//注:rlt是查询出来的所有数据的集合source.Load(rlt.Take(PageSize)); //第一次加载时候的数据,首次加载的时候只要Take每页的数据//点击下一页时source.Load(rlt.Take(PageSize)); //这句也要的if (CurrentPage <(RecordCount-1 )) //这是我点下页的时候                CurrentPage++;           bindingSource.DataSource = rlt.Skip((CurrentPage)* PageSize)).Take(PageSize); //再把这个值赋给数据源,因为我是用bindingSource绑—ataGrideView的 

读书人网 >.NET

热点推荐