每当应用程序调用
时,我都会有一致的,可重复的120秒挂起 this.cacheProvider.Add(new CacheItem(cacheKey, data, this.regionName), cachePolicy);
在CachedDataSource.cs of the sample.的第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”引用和ContextGenerator to my DAL升级到4.1。
如果我撤消这些更改,那么我的应用程序会立即生效。
我的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);
}
}
问题
这是一个错误,还是我正在使用EF4.1或错误的缓存层?
答案 0 :(得分:0)
您提到数据是IQueryable的结果。您是否尝试先将数据执行.ToList(),然后再将其发送到缓存中?