/// <summary> /// Exports the specified entity map. /// </summary> /// <param name="entityMap">The entity map.</param> /// <param name="exportIdentityColumn">if set to <c>true</c> [export identity column].</param> /// <param name="exportDatabaseGeneratedColumn">if set to <c>true</c> [export database generated column].</param> /// <returns></returns> public ExportModel Export(EntityMap entityMap, bool exportIdentityColumn = true, bool exportDatabaseGeneratedColumn = true) { var model = new ExportModel { ImportDialect = importDialect, ExportDialect = exportDialect, Map = entityMap, TypeConverterStore = typeConverter }; model.Options.ExportIdentityColumn = exportIdentityColumn; model.Options.ExportDatabaseGeneratedColumns = exportDatabaseGeneratedColumn; IDbAccess dbAccess = new DbAccess(dbConnector); using (var conn = dbConnector.CreateNewConnection()) { if (conn.State != ConnectionState.Open) { conn.Open(); } var dataBag = dbAccess.ExecuteDictionary(conn, model.SelectSqlStatement()); model.DataBag = dataBag; } return(model); }
/// <summary> /// Opens the connection. /// </summary> /// <returns></returns> public DbConnection OpenConnection() { if (!HasOpenConnection) { if (!userProvidedConnection) { currentConn = dbConnector.CreateNewConnection(); } if (currentConn.State == ConnectionState.Open) { logger.Log(LogLevel.Info, "Current connection is already open."); } else { currentConn.Open(); } HasOpenConnection = true; } else { if (currentConn.State == ConnectionState.Broken) { try { currentConn.Close(); } catch (Exception ex) { logger.Error("Closing broken connection failed.", ex); } currentConn = dbConnector.CreateNewConnection(); currentConn.Open(); } else if (currentConn.State == ConnectionState.Closed) { currentConn = dbConnector.CreateNewConnection(); currentConn.Open(); } } return(currentConn); }