gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 和 EF 的缓存

转载 作者:行者123 更新时间:2023-12-04 14:41:45 24 4
gpt4 key购买 nike

我很关心 EF 结果的缓存,这是默认设置。我有以下存储库:

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();
}
}

和以下带有方法的 Controller :

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();
}
}

据我所知,在第一次调用 Statuses 方法后,结果应该被缓存,但我在 SQL 配置文件中看到:

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

哪里不对?

最佳答案

如您所知,EF 不缓存结果集,尽管我一直想看看这个:http://code.msdn.microsoft.com/EFProviderWrappers-c0b88f32

关于asp.net-mvc - ASP.NET MVC 和 EF 的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7703517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com