1

我在 asp.net mvc 网站的应用程序启动例程中缓存了特定的 EF 实体列表。

protected void Application_Start()
{
   CountriesDbContext db = new CountriesDbContext();
   HttpRuntime.Cache["Countries"] = db.Countries.ToList();
}

当我像下面这样请求时,我会放松对口音不敏感的行为

private List<Country> cache = (List<Country>)HttpRuntime.Cache["Countries"];
//Accent insensitive behaviour is lost ! 
results = cache.Where(c => c.FR.ToLower()
               .Contains(search.ToLower())); //for example : e will not match é

如果我使用 dbContext “通常”请求它,则保留不区分重音的行为。

private CountriesDbContext db = new CountriesDbContext();
//Accent insensitive behaviour search 
results = db.Countries.Where(c => c.FR.ToLower()
               .Contains(search.ToLower())); //for example : e will match é

这是为什么 ?以及如何在缓存实体时保留对口音不敏感的行为?

4

1 回答 1

1

排序规则是一个 SQL Server 概念,这就是为什么查询适用于数据库数据,而不适用于内存数据,其中 .Net 比较适用。

因此,您需要在.Net 中为您的缓存实现一个不区分重音的比较器,如this answer中所述。

于 2012-12-05T10:05:12.037 回答