IQueryable with Entity Framework - order, where, skip and take have no effect

自古美人都是妖i 提交于 2019-12-25 20:03:26

问题


I'm using Entity Framework (code first) like this:

IQueryable<StammdatenEntityModel> query = dbSet;

query.OrderByDescending(s => s.CreateDateTime);

query.Where(s => s.Deleted == false);

if(!String.IsNullOrEmpty(keyword))
{
    query.Where(s => s.SerialNumber.Contains(keyword)); //simplified for SO
}

query.Skip(skip);
query.Take(take);

However the OrderByDescending, Where, Skip and Take don't have any effect.


回答1:


You are not using the result of query

IQueryable<StammdatenEntityModel> query = dbSet;
query = query.OrderByDescending(s => s.CreateDateTime);
query = query.Where(s => s.Deleted == false);
if(!String.IsNullOrEmpty(keyword))
{
    query = query.Where(s => s.SerialNumber.Contains(keyword)); //simplified for SO
}
query = query.Skip(skip);
query = query.Take(take);


来源:https://stackoverflow.com/questions/45432279/iqueryable-with-entity-framework-order-where-skip-and-take-have-no-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!