Azure 使用Microsoft.ApplicationServer.Caching.DataCacheFactory时,EF4.1挂起120秒
每当应用程序调用时,我都有一个一致的、可重复的120秒挂起Azure 使用Microsoft.ApplicationServer.Caching.DataCacheFactory时,EF4.1挂起120秒,azure,entity-framework-4.1,azure-appfabric,Azure,Entity Framework 4.1,Azure Appfabric,每当应用程序调用时,我都有一个一致的、可重复的120秒挂起 this.cacheProvider.Add(new CacheItem(cacheKey, data, this.regionName), cachePolicy); 在报告的第60行。.Add方法是Microsoft的DLL内部的,我没有代码。以下是我的参数: cacheKey = "listofCompanies" data = // this is an EF 4.0 database first model class w
this.cacheProvider.Add(new CacheItem(cacheKey, data, this.regionName), cachePolicy);
在报告的第60行。.Add
方法是Microsoft的DLL内部的,我没有代码。以下是我的参数:
cacheKey = "listofCompanies"
data = // this is an EF 4.0 database first model class with 70 entries... result from IQueryable
this.regionName = "companies"
再现错误:
我有一个数据库第一个EF4.0项目,最近通过添加“EntityFramework”引用和
如果我撤消这些更改,那么我的应用程序将立即运行
DAL和存储库存储在MVC应用程序的单独DLL中。不确定这是否是问题的一部分
关于我的存储库
/// Sample repository. Note that I return List<T> as IEnumerable,
/// and I use IDisposable
///
public class CompanyRepository : DisposableBase, ICompanyRepository
{
public IEnumerable<CompanyDetail> GetOneCompany(int? CompanyID)
{
var t = from c in _entities.CompanyDetail
where c.CompanyID == CompanyID.Value
select c;
return t.ToList();
}
}
/// <summary>
/// Disposable implementation based on advice from this link:
/// from Http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
/// </summary>
public class DisposableBase : IDisposable
{
protected TLSAdminEntities1 _entities;
public DisposableBase()
{
_entities = new TLSAdminEntities1();
disposed = false;
}
private bool disposed ;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
_entities.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
///示例存储库。请注意,我将列表返回为IEnumerable,
///我使用IDisposable
///
公共类公司存储库:DisposableBase,ICompanyRepository
{
公共IEnumerable GetOneCompany(int?CompanyID)
{
var t=来自c in_entities.CompanyDetail
其中c.CompanyID==CompanyID.Value
选择c;
返回t.ToList();
}
}
///
///基于此链接建议的一次性实施:
///从Http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
///
公共类DisposableBase:IDisposable
{
受保护的TLSAdminenties 1_实体;
公共可处置基地()
{
_实体=新的TLSAdminenties1();
已处理=错误;
}
私人住宅;
受保护的虚拟void Dispose(bool disposing)
{
如果(!this.disposed)
{
如果(处置)
{
_实体。Dispose();
}
}
这是真的;
}
公共空间处置()
{
处置(真实);
总干事(本);
}
}
问题
这是一个bug,还是我使用了EF4.1,或者缓存层不正确?您提到数据是IQueryable的结果。在将数据发送到缓存之前,您是否尝试先对数据执行.ToList()?提供出现问题的真实代码。@LadislavMrnka真实代码是CachedDataSourceSample。。它是SDK的一部分。要添加设计器,我必须上传一个项目。我应该把这样一个项目放在哪里?我不是说你应该提供整个源代码,而是一些与这个问题相关的代码片段。没有人会去下载任何特定的SDK或示例来诊断您的问题。@LadislavMrnka我必须考虑分享什么来解释我的问题。问题出在MSFT AppFabric缓存的内部。我使用相同的参数调用它,但简单地说,如果存在ContextGenerator,那么.Add方法的长度为120秒。如果我删除EF 4.1,.Add()需要不到1秒的时间。在这种情况下,请比较数据库活动、实体的实现或使用一些探查器来查看应用程序中发生了什么。我确实使用了
.ToList()
。MSFT缓存要求所有数据都是可序列化的,而iquirable似乎不是。我添加了一个示例存储库