Ejemplo n.º 1
0
        /// <summary>Method create and open context for database.</summary>
        /// <param name="accessConfigurations">Parameters to database connect.</param>
        /// <returns>Created context. null if fail.</returns>
        public DbContext Initizlize(DatabaseConfig accessConfigurations)
        {
            EntityConnectionStringBuilder connection = UpdateConnectionParameters(accessConfigurations);

            try
            {
                _Context = new DragonflyEntities(connection.ToString());
                _Context.Database.Connection.Open();
            }
            catch (Exception ex)
            {
                if (_Context != null)
                {
                    _Context.Dispose();
                }
                return(null);
            }
            return(_Context);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method generate a new db context.
        /// </summary>
        /// <param name="accessConfigurations">Settings to db access.</param>
        /// <returns>Db context.</returns>
        /// <exception cref="DbInitializationException"/>
        public DragonflyEntities GenerateContext()
        {
            DragonflyEntities             context    = null;
            EntityConnectionStringBuilder connection = UpdateConnectionParameters(_DbConfig);

            try
            {
                context = new DragonflyEntities(connection.ToString());
                context.Database.Connection.Open();
            }
            catch (Exception ex)
            {
                if (context != null)
                {
                    context.Dispose();
                }
                throw new DbInitializationException(ex.Message);
            }
            return(context);
        }