EF5 是否有可能在使用 DBContext 时不会立即关闭连接
public void UpdateCategory(Models.Category catData)
{
if (catData == null) return;
using (var cntx = new DataContext())
{
//IN THE LINE BELOW A CONNECTION IS DEFINITELY OPENED BUT IS IT IMMEDIATELY CLOSE????
var cat = cntx.Set<Category>().FirstOrDefault(c => c.CategoryId == catData.CategoryId);
if (cat == null) return;
if (!cat.LastChanged.Matches(catData.LastChanged))
throw new ConcurrencyException(cat.GetType().ToString());
cat.CategoryName = catData.CategoryName;
cntx.DbContext.Entry<Category>(cat).State = System.Data.EntityState.Modified;
//AFTER THE NEXT LINE DO I HAVE 2 CONNECTIONS OPENED? OR WAS THE CONNECTION OPENED FROM THE FIRST QUERY CLOSED ALREADY?
cntx.SaveChanges();
catData.LastChanged = cat.LastChanged;
}
}
是否存在相同上下文创建\打开 2 个连接而留下一个打开的场景\错误?