C# mvc dbcontext在Azure上不工作
我正在创建一个processor类并在worker角色中运行。 在处理器内部,我创建了reporstory来对我的数据库执行CRUD操作 我有两个存储库,product和productsize,dbcontext在product repo中创建,并传递到product size 在我的本地计算机上一切正常,但是当我部署到Azure时,系统会向我抛出以下错误:C# mvc dbcontext在Azure上不工作,c#,asp.net-mvc,entity-framework,dbcontext,C#,Asp.net Mvc,Entity Framework,Dbcontext,我正在创建一个processor类并在worker角色中运行。 在处理器内部,我创建了reporstory来对我的数据库执行CRUD操作 我有两个存储库,product和productsize,dbcontext在product repo中创建,并传递到product size 在我的本地计算机上一切正常,但是当我部署到Azure时,系统会向我抛出以下错误: System.InvalidOperationException: The operation cannot be completed b
System.InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
processor.cs
public class Processor : IDisposable
{
private readonly IProductRepository _productRepository;
public Processor()
: this(new ProductRepository())
{
}
public Processor(
IProductRepository productRepository
)
{
_productRepository = productRepository;
}
public void Run(){ _productRepository.someoperation;}
public void Dispose()
{
_productRepository.Dispose();
}
productrepository.cs
public class ProductRepository : IProductRepository
{
private static readonly DbContext_context = new DbContext();
private readonly IProductSizeRepository _productSizeRepository;
public ProductRepository()
: this(
new ProductSizeRepository(_context))
{
}
public ProductRepository(
IProductSizeRepository productSizeRepository
)
{
_pictureRepository = pictureRepository;
}
public void Dispose()
{
_context.Dispose();
_productSizeRepository.Dispose();
}
在workerrole.cs while循环中
使用(var runner=new Processor())
{
runner.Run();
}需要将所有参考副本设置为local=true
并在代码中而不是在构造函数中启动dbcontext您是SQL Server数据库吗?您仍然在使用SQL Server Compact Edition(SCSE)吗在云中??如何将连接字符串传递到DbContext?在
\u context
中的某个地方是否有一些using语句?我们错过了ProductRepository