问题描述
让我们说我有这三种方法: public Customer GetCustomerByCustomerGuid(Guid customerGuid)
{
返回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()
{
从_customerRepository.Table中的r返回选择r;
}
//_customerRepository.Table是这样的:
public IQueryable< T>表
{
get {return Entities; }
}
每当我拨打电话时,都会对数据库发出查询GetCustomerByEmailAddress() / GetCustomerByCustomerGuid()
或者EF缓存 GetCustomer()
并查询我的信息?
另一方面,它会将每个调用的结果缓存到 GetCustomerByEmailAddress ()
/ GetCustomerByCustomerGuid()
我正在尝试建立手册缓存我应该去,我真的不喜欢运行更多的SQL查询比绝对必要。
它将导致一个调用数据库每次。我今天早些时候问过类似的问题,你可以在这里看到更多的内容:
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; }
}
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?
On the other hand, would it just cache the result of each call to GetCustomerByEmailAddress()
/ GetCustomerByCustomerGuid()
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.
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?
这篇关于查询实体框架缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!