使用ODAC版本是 ODAC1120230Beta_EntityFramework
Entity Framework版本是EntityFramework 4.1
然后 {DbContext}.Set<T>().Where(..).OrderBy(..).Skip(..).Take(..);这样的方法分页,跟踪发现生成的是这样的语句。。
SELECT
"Extent1"."ID" AS "ID",
"Extent1"."Time" AS "Time",
....
FROM ( SELECT "Extent1"."ID" AS "ID", "Extent1"."Time" AS "Time",...., ROWNUM AS "row_number"
FROM "FS"."TEST_TABLE" "Extent1"
) "Extent1"
WHERE ("Extent1"."row_number" > 0) AND (ROWNUM <= (20) )
ORDER BY "Extent1"."Time" ASC
最里层的是没有排序信息的,所以得到的结果列表根本不是按Time字段排序后分页的结果,这是程序的调用方式有问题还是ODAC的问题?有什么解决方法么?
把你的Linq语句写出来看下是不是有问题。
分页方法如下:
public IEnumerable<TEntity> RetrievePagedData<TPropertySorting>(int pageIndex,int pageSize,ISpecification<TEntity> condition,Expression<Func<TEntity, TPropertySorting>> orderByExpression,out int totalCount)
var query = _context.Set<TEntity>()
.where(condition.SatisfiedBy())
.OrderBy(orderByExpression);
int totalCount = query.Count();//记录总数,out参数返回
return query.Skip((pageIndex-1)*pageSize).Take(pageSize);//pageIndex和pageSize是传入的参数
}