protected IEnumerable <TEntity> ExecuteQuery(SqlCommand command) { using (SqlConnection connection = new SqlConnection(_dbConfig.GetConnectionString())) { command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { List <TEntity> items = new List <TEntity>(); while (reader.Read()) { var item = CreateEntity(); Map(reader, item); items.Add(item); } return(items); } finally { reader.Close(); } } }
/// <summary> /// Return a new instance of DbProviderFactory created from dbConfig settings /// </summary> /// <param name="dbConfig"></param> /// <param name="withAdminPrivileges">If true, a DbProviderFactory with AdminConnectionString is build</param> /// <returns></returns> public static DbProviderFactory GetDbProviderFactory(this IDbConfig dbConfig, bool withAdminPrivileges = false) { var dbType = dbConfig.DbType; AssertDbProviderFactoryImplemented(dbType); var connectionString = withAdminPrivileges ? dbConfig.GetAdminConnectionString() : dbConfig.GetConnectionString(); var dbProviderFactory = new FluentDbProviderFactory(DbProviderFactories[dbType], connectionString); return(dbProviderFactory); }