Beispiel #1
0
        /// <summary>
        /// 回滚
        /// </summary>
        /// <param name="dbName"></param>
        public static void Rollback(string dbName)
        {
            CheckDbName(dbName);

            string key = GetKey(dbName);

            if (!ServiceContext.Current.Contains(key))
            {
                throw new InvalidOperationException(string.Format("数据库{0}的上下文环境不存在。", dbName));
            }

            DataAccessContext dac = ServiceContext.Current[key] as DataAccessContext;

            if (dac == null)
            {
                throw new Exception("DataAccessContext is null");
            }

            try
            {
                dac.Rollback();
            }
            finally
            {
                dac.CloseConnection();

                ServiceContext.Current.Remove(key);
            }
        }