【发布时间】:2017-08-07 12:52:28
【问题描述】:
我正在使用带有 LazyLoadEnabled = false 配置的实体框架 6。我在我的项目中使用 UnitOfwork 存储库模式。
我在一个表中有大约 1,50,000 条记录,与大约 5 个表有外键关系。现在我的要求是我必须实现服务器端分页。为此,首先我在应用一些基本过滤器(如 isactive 和由用户创建)后查询此表以获取准确计数,如下所示:
public long Count(Func<TEntity,bool> where)
{
return DbSet.Where(where).Count();
}
然后我正在应用一些搜索字符串过滤器并包括一些外部引用,如下所示:
public IQueryable<TEntity> GetWithInclude(Expression<Func<TEntity, bool>> predicate, params string[] include)
{
IQueryable<TEntity> query = this.DbSet;
query = include.Aggregate(query, (current, inc) => current.Include(inc));
return query.Where(predicate);
}
但是在这两种方法中,我都得到了OutOfMemory exception,因为我使用了Where 子句。请帮我解决这个问题。
【问题讨论】:
标签: c# sql entity-framework out-of-memory