Reputation: 9011
I heart about caching of EF results and that it's by default. I have the following repository:
public class Model1Repository
{
private NEOGOV_IdeasEntities _dataContext;
public Model1Repository()
{
_dataContext = new NEOGOV_IdeasEntities();
}
public List<Status> Statuses()
{
var query = from i in _dataContext.Statuses select i;
return query.ToList();
}
}
and the following controller with method:
public class TestController : Controller
{
private NEOGOV_Ideas.Models.Model1Repository _repository;
public TestController()
{
_repository = new NEOGOV_Ideas.Models.Model1Repository();
}
public ActionResult Test1()
{
_repository.Statuses();
_repository.Statuses();
_repository.Statuses();
_repository.Statuses();
return View();
}
}
as I understand, after first call of Statuses method results should be cached but I see in SQL profile:
exec sp_reset_connection
go
SELECT
[Extent1].[StatusID] AS [StatusID],
[Extent1].[StatusName] AS [StatusName]
FROM [dbo].[Statuses] AS [Extent1]
go
exec sp_reset_connection
go
SELECT
[Extent1].[StatusID] AS [StatusID],
[Extent1].[StatusName] AS [StatusName]
FROM [dbo].[Statuses] AS [Extent1]
go
exec sp_reset_connection
go
SELECT
[Extent1].[StatusID] AS [StatusID],
[Extent1].[StatusName] AS [StatusName]
FROM [dbo].[Statuses] AS [Extent1]
go
exec sp_reset_connection
go
SELECT
[Extent1].[StatusID] AS [StatusID],
[Extent1].[StatusName] AS [StatusName]
FROM [dbo].[Statuses] AS [Extent1]
go
what is incorrect?
Upvotes: 3
Views: 1000
Reputation: 24433
As you have found out, EF does not cache result sets, although I have been meaning to take a look at this: http://code.msdn.microsoft.com/EFProviderWrappers-c0b88f32
Upvotes: 3