我正在使用LINQ在我的网站上进行分页数据。我目前正在使用skip()和take()执行分页。现在,我想使用缓存依赖项缓存数据,以使缓存将无效,如果数据更改。但是SQL Server的 查询通知 不支持顶部表达式。是否有其他方法可以与LINQ查询一组未生成顶部的数据集?还是缓存此数据的另一种方法使其无效?

有帮助吗?

解决方案

将数据拉到两次中:

// step1: get the IDs of the items in the current page.
List<int> customerIds = db.Customers
  .Where(filter)
  .OrderBy(c => c.FirstName)
  .ThenBy(c => c.CustomerID)
  .Select(c => c.CustomerID)
  .Skip(200)
  .Take(20)
  .ToList();

// step2: get the items for that page
List<Customer> customers = db.Customers
  .Where(c => customerIds.Contains(c.CustomerID))
  .ToList();

其他提示

缓存整个结果设置,并将其设置为SQLDEPDENS。

从缓存中读取整个集合,然后对此使用Skip/Take。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top