/// <summary> /// Adds an entity and its child entities to the stubbed result set. /// NOTE: All entity values will be added to a single stubbed row. /// </summary> /// <param name="entities">A set of parent and child entities that will create a single stubbed row.</param> public void AddEntityWithChildren(params object[] entities) { var reflector = new Marr.Data.Reflection.CachedDelegateReflectionStrategy(); List<object> stubbedValues = new List<object>(); foreach (object entity in entities) { Type entityType = entity.GetType(); AddFieldNames(entityType); var mappings = Marr.Data.MapRepository.Instance.GetColumns(entity.GetType()); if (mappings.Count == 0) { string error = string.Format("The entity type '{0}' does not have any column mappings.", entityType.Name); throw new ArgumentException(error); } foreach (var column in _columns.Where(c => c.Type == entityType)) { ColumnMap mapping = null; if (!column.IsAlt) { mapping = mappings.Where(m => m.ColumnInfo.Name == column.Map.ColumnInfo.Name).FirstOrDefault(); } else { mapping = mappings.Where(m => m.ColumnInfo.AltName == column.Map.ColumnInfo.AltName).FirstOrDefault(); } if (mapping != null) { object val = reflector.GetFieldValue(entity, column.Map.FieldName); stubbedValues.Add(val); } } } AddRow(stubbedValues.ToArray()); _columnIndex = 0; }
/// <summary> /// Adds an entity and its child entities to the stubbed result set. /// NOTE: All entity values will be added to a single stubbed row. /// </summary> /// <param name="entities">A set of parent and child entities that will create a single stubbed row.</param> public void AddEntityWithChildren(params object[] entities) { var reflector = new Marr.Data.Reflection.CachedDelegateReflectionStrategy(); List <object> stubbedValues = new List <object>(); foreach (object entity in entities) { Type entityType = entity.GetType(); AddFieldNames(entityType); var mappings = Marr.Data.MapRepository.Instance.GetColumns(entity.GetType()); if (mappings.Count == 0) { string error = string.Format("The entity type '{0}' does not have any column mappings.", entityType.Name); throw new ArgumentException(error); } foreach (var column in _columns.Where(c => c.Type == entityType)) { ColumnMap mapping = null; if (!column.IsAlt) { mapping = mappings.Where(m => m.ColumnInfo.Name == column.Map.ColumnInfo.Name).FirstOrDefault(); } else { mapping = mappings.Where(m => m.ColumnInfo.AltName == column.Map.ColumnInfo.AltName).FirstOrDefault(); } if (mapping != null) { object val = reflector.GetFieldValue(entity, column.Map.FieldName); stubbedValues.Add(val); } } } AddRow(stubbedValues.ToArray()); _columnIndex = 0; }