private async Task <IEnumerable <PTableMetadata> > GetMetaData(IMetaDataInitializer initializer, CancellationToken cancellationToken) { var result = new List <PTableMetadata>(); using (var uof = _uowFactory.GetUnitOfWork()) { var metaTables = uof.GetSchemaAsync("Tables", cancellationToken); var metaColumns = uof.ExecuteReaderAsync(MSSQLSourceSchema.sqlPKColumns, cancellationToken); await Task.WhenAll(metaColumns, metaTables); var dt = new DataTable(); dt.Load(metaColumns.Result); var iList = dt.Rows.Cast <DataRow>(); foreach (DataRow t in metaTables.Result.Rows) { var pTab = new PTableMetadata() { TableName = t["table_name"].ToString() }; foreach (DataRow c in iList.Where(_ => _["TableName"].ToString() == pTab.TableName && !_globalConfiguration.FieldsToExclude.Any(f => f == _["ColumnName"].ToString()))) { var field = initializer.InitTableMetaData(c); pTab.Add(field); } var uqCol = _globalConfiguration.UniqueColums.FirstOrDefault(_ => _.TableName == pTab.TableName); if (uqCol != null) { pTab.UniqueColumnsCollection = new List <string>(uqCol.UniqueColumns); } result.Add(pTab); } } return(result); }
public async Task <PTableMetadata> GetTableMetaData(string tableName, CancellationToken cancellationToken) { string sql = string.Format("{0} and object_name(C.[object_id]) = '{1}'", MSSQLSourceSchema.sqlPKColumns, tableName); using (var uof = _uowFactory.GetUnitOfWork()) using (var dr = await uof.ExecuteReaderAsync(sql, cancellationToken)) { var ptable = new PTableMetadata() { TableName = tableName }; var dt = new DataTable(); dt.Load(dr); foreach (DataRow r in dt.Rows) { var field = _initializer.InitTableMetaData(r); ptable.Add(field); } return(ptable); } }