关于实体框架缓存查询 [英] Query about Entity Framework caching
问题描述
可以说我有这三种方法:
Lets say I have these three methods:
public Customer GetCustomerByCustomerGuid(Guid customerGuid)
{
return GetCustomers().FirstOrDefault(c => c.CustomerGuid.Equals(customerGuid));
}
public Customer GetCustomerByEmailAddress(string emailAddress)
{
return GetCustomers().FirstOrDefault(c => c.EmailAddress.Equals(emailAddress, StringComparison.OrdinalIgnoreCase));
}
public IEnumerable<Customer> GetCustomers()
{
return from r in _customerRepository.Table select r;
}
//_customerRepository.Table is this:
public IQueryable<T> Table
{
get { return Entities; }
}
这会导致数据库查询每次我做出通话GetCustomerByEmailAddress()
/ GetCustomerByCustomerGuid()
或将EF缓存 GetCustomer的结果()
和查询,对我的信息?
Would this cause a query to the database each time I make a call to GetCustomerByEmailAddress()
/ GetCustomerByCustomerGuid()
or would EF cache the results of GetCustomer()
and query that for my information?
在另一方面,它只是缓存每次通话的结果 GetCustomerByEmailAddress()
/ GetCustomerByCustomerGuid()
On the other hand, would it just cache the result of each call to GetCustomerByEmailAddress()
/ GetCustomerByCustomerGuid()
我试图建立手动缓存我应该去,我真的不喜欢多运行SQL查询比是绝对必要的水平。
I am trying to establish the level of manual caching I should go to, I really dislike running more SQL queries than are absolutely necessary.
推荐答案
这将导致每一次对数据库的调用。我居然问过类似的问题今天早些时候,你可以看到更多在这里:<一href=\"http://stackoverflow.com/questions/21707970/why-does-entity-framework-6-x-not-cache-results\">Why做实体框架6.x中不缓存的结果?
It will result in a call to the database every time. I actually asked a similar question earlier today and you can see more here: Why does Entity Framework 6.x not cache results?
这篇关于关于实体框架缓存查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!