我在 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 é
这是为什么 ?以及如何在缓存实体时保留对口音不敏感的行为?