【发布时间】:2014-03-08 06:14:14
【问题描述】:
场景:
我有一个自定义DbContext。我正在使用底层ObjectContext 的StoreConnection 属性来运行修改多个实体的存储过程(在我的自定义DbContext 中有一个DbSet)。我的 DbContext 和存储库由 Unity v3 提供。
示例:
private MyContext _ctx;
private IGenericRepository<Foo>();
private IGenericRepository<Bar>();
public void DoSomethingFooAndBar()
{
var connection = _ctx.StoreConnection; //Exposed ObjectContext.StoreConnection in my custom context
using (var cmd = connection.CreateCommand())
{
command.CommandText = "dbo.ModifyFooAndBar";
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
}
//What is the state of my DbSet<Foo> and DbSet<Bar>?
}
问题:
在这个存储过程之后我是否会冒着DbContext 过时的风险,如果是这样,我如何让它成为当前的,而不是处理它并创建一个新的?
【问题讨论】:
标签: c# entity-framework stored-procedures dbcontext entity-framework-6