public TableReader(RfcDestination conn, string tableName) { _conn = conn; _tableName = tableName; _accesor = TypeAccessor.Create(_rowType); _members = _accesor.GetMembers(); _memberByName = _members .ToDictionary(m => m.Name); _memberByAlias = _members .ToDictionary(m => TableReaderExtensions.GetColumnName(m)); _peakConnectionsLimit = Convert.ToInt32(_conn.Parameters[RfcConfigParameters.PeakConnectionsLimit]); }
/// <summary> /// Provided an array of entities will set the condition to retrieve the same entities based in the primary key /// Handy to retrieve the same rows (with same primary keys) of the same table between different SAP systems /// </summary> public TableReader <T> WhereByKeys(IEnumerable <T> entities) { //Remove duplicated entries entities = entities .ToLookup(e => TableReaderExtensions.SerializeKeyColumns(e)) .Select(e => e.First()); var keyCols = TableReaderExtensions.GetKeyColumns <T>(); if (keyCols.IsEmpty()) { throw new ArgumentException($"At least one property of {_rowType.Name} must have the 'Key' attribute."); } _condition = new WhereBuilder(); if (keyCols.IsEmpty()) { throw new ArgumentException(); } foreach (var row in entities) { var expression = string.Empty; foreach (var keyCol in keyCols) { var propVal = _accesor[row, keyCol]; expression += $"{keyCol} = " + (propVal.GetType().IsNumber() ? propVal : $"'{propVal}'") + " AND "; } expression = expression.ReplaceLastOccurrence(" AND ", string.Empty); (_condition.Conditions as List <string>).Add(expression); } return(this); }