Join or Mutible DBContext Repository Generic c#

前端 未结 2 1759
我在风中等你
我在风中等你 2020-12-22 14:04

I have repository generic where I do method as Get,Update,Insert.

I get a data from table in data base I use this method.

 public IEnumerable

        
2条回答
  •  爱一瞬间的悲伤
    2020-12-22 14:30

    The solution you found is slow because the repository method is materializing/executing the query immediately instead of allowing deferred execution to occur. Try removing the ".ToList()" from the query within the repository method:

    public IEnumerable Get(Expression> newObjectEntity,int page, int rowsByPage) where typeEntity : class
    {
       IEnumerable Result = null;
            Result = Context.Set().Where(newObjectEntity).OrderBy(m => true).Skip(5 * (page - 1)).Take(rowsByPage);
        return Result;
    }
    

    This will allow you to compose and construct higher order queries without pulling the whole table into memory immediately.

提交回复
热议问题