【发布时间】:2014-03-09 23:54:05
【问题描述】:
假设我有这三种方法:
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() 的结果并查询我的信息?
另一方面,它是否只是缓存每次调用GetCustomerByEmailAddress()/GetCustomerByCustomerGuid()的结果
我正在尝试建立我应该达到的手动缓存级别,我真的不喜欢运行比绝对必要的更多的 SQL 查询。
【问题讨论】:
标签: c# asp.net-mvc entity-framework caching asp.net-mvc-5