private void RemoveDeletedRemoteEntriesToLocal(SDSchemaObject data) { var removedTables = _efContext.SDStatuses .Where(s => !data.SDDataTables.Any(t => t.Id == s.Id)) .Select(s => _efContext.SDDataTables.SingleOrDefault(t => t.Id == s.Id)) .Where(s => s != null) .ToList(); var removedColumns = _efContext.SDStatuses .Where(s => !data.SDDataTables.SelectMany(t => t.Columns).Any(c => c.Id == s.Id)) .Select(i => _efContext.SDColumns.SingleOrDefault(c => c.Id == i.Id)) .Where(i => i != null) .Where(c => !removedTables.Any(t => t.Id != c.SDDataTableId)) .ToList(); foreach (var table in removedTables) { _dbTableRepository.Remove(table); _efContext.SDDataTables.Remove(table); _efContext.SDStatuses.Remove(new SDStatus(table.Id)); _efContext.SDStatuses.RemoveRange(table.Columns.Select(c => new SDStatus(c.Id))); } foreach (var column in removedColumns) { var tableName = _efContext.SDDataTables.Single(t => t.Id == column.SDDataTableId).Name; _dbTableRepository.RemoveColumn(tableName, column); _efContext.SDColumns.Remove(column); _efContext.SDStatuses.Remove(new SDStatus(column.Id)); } _efContext.SaveChanges(); }
internal void DropColumn(DataTable dataTable, string columnName) { var sdDataTable = _efContext.SDDataTables.Single(c => c.Name == dataTable.TableName); var column = _efContext.SDColumns.Single(c => c.SDDataTableId == sdDataTable.Id && c.Name == columnName); _dbTableRepository.RemoveColumn(dataTable.TableName, column); _efContext.SDColumns.Remove(column); _efContext.SaveChanges(); dataTable.Columns.Remove(columnName); }