我有以下查询:
if (idUO > 0)
{
query = query.Where(b => b.Product.Center.UO.Id == idUO);
}
else if (dependencyId > 0)
{
query = query.Where(b => b.DependencyId == dependencyId );
}
else
{
var dependencyIds = dependencies.Select(d => d.Id).ToList();
query = query.Where(b => dependencyIds.Contains(b.DependencyId.Value));
}
[...] <- Other filters...
if (specialDateId != 0)
{
query = query.Where(b => b.SpecialDateId == specialDateId);
}
所以,我在这个查询中有其他过滤器,但最后,我在数据库中处理查询:
return query.OrderBy(b => b.Date).Skip(20 * page).Take(20).ToList(); // the returned object is a Ticket object, that has 23 properties, 5 of them are relationships (FKs) and i fill 3 of these relationships with lazy loading
当我访问第一个page
时,它可以,查询不到一个 1 秒,但是当我尝试访问页面 30000 时,查询需要超过 20 秒。linq 查询中有一种方法可以提高查询的性能吗?还是仅在数据库级别?而在数据库层面,对于这种查询,提高性能最好的方法是什么?