Ejemplo n.º 1
0
        /// <summary>
        /// Close all db context
        /// </summary>
        public static void CloseAllDbContext(IDALContainer dalContainer)
        {
            HttpContext context = HttpContext.Current;

            if (context != null && context.Session != null)
            {
                EFDbContextStorage ctxStorage = context.Session[STORAGE_KEY] as EFDbContextStorage;

                if (ctxStorage != null)
                {
                    foreach (EFDbContext ctx in ctxStorage.GetAllDbContexts())
                    {
                        if (ctx.Database.Connection.State == System.Data.ConnectionState.Open)
                        {
                            ctx.Database.Connection.Close();
                        }

                        ctx.Dispose();
                    }

                    context.Session.Remove(STORAGE_KEY);
                }
            }
            else if (dalContainer != null)
            {
                dalContainer.Close();
                dalContainer.Dispose();
            }
        }
Ejemplo n.º 2
0
 protected override void Dispose(bool disposing)
 {
     if (DALContainer != null)
     {
         DALContainer.Close();
         DALContainer.Dispose();
         DALContainer = null;
     }
     base.Dispose(disposing);
 }