使用Microsoft.ApplicationServer.Caching.DataCacheFactory时,EF4.1会挂起120秒

时间:2011-11-15 03:41:21

标签: azure entity-framework-4.1 azure-appfabric

每当应用程序调用

时,我都会有一致的,可重复的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或错误的缓存层?

1 个答案:

答案 0 :(得分:0)

您提到数据是IQueryable的结果。您是否尝试先将数据执行.ToList(),然后再将其发送到缓存中?