internal static MappedNestedResults CompileNestedResults(NestedResultsDefinition nestedResultsMapping, QueryDefinition queryParent) { if (nestedResultsMapping == null) { throw new ArgumentNullException("nestedResultsMapping cant be null"); } if (!(queryParent is QueryWithNestedResultsDefinition)) { throw new ArgumentException("No parent defintion of type QueryWithNestedResultsDefinition found"); } MappedNestedResults newNestedResults = new MappedNestedResults(nestedResultsMapping.IdColumn); var template = nestedResultsMapping.Template; CompileProperties(template, newNestedResults, queryParent); return(newNestedResults); }
internal void WriteNestedResult(MappedProperty prop, MappedNestedResults mappedGroup, JsonTextWriter jsonWriter, RowSet rowSet, List <string> fieldNameList, ParentObject parent, IDictionary <string, object> context) { HashSet <object> ids = new HashSet <object>(rowSet.Rows.Select(r => r[mappedGroup.IdColumn]).Where(v => v != null && v != System.DBNull.Value)); if (ids.Count() > 0) { jsonWriter.WritePropertyName(prop.TargetPropertyName); jsonWriter.WriteStartArray(); foreach (var currentId in ids) { var filteredRowSet = new RowSet(mappedGroup.IdColumn, rowSet.Rows.Where(r => r[mappedGroup.IdColumn].Equals(currentId)).ToList()); WriteJsonObject(mappedGroup, jsonWriter, rowSet.Rows.First(r => r[mappedGroup.IdColumn].Equals(currentId)), filteredRowSet, fieldNameList, parent, context); } jsonWriter.WriteEndArray(); } }
public IJsonMappingBuilder NestedResults(string propertyName, string idColumn, Action <IJsonMappingBuilder> config) { if (propertyName == null) { throw new ArgumentNullException("propertyName cant be null"); } if (idColumn == null) { throw new ArgumentNullException("idColumn cant be null"); } if (config == null) { throw new ArgumentNullException("config cant be null"); } AssertParentMappingHasType <MappedQueryWithNestedResults>(this, propertyName, "NestedResults"); var builder = new JsonMappingBuilder(this); var mappedNestedResults = new MappedNestedResults(idColumn); builder.Result = mappedNestedResults; Result.MappedPropertyList.Add(new MappedProperty(propertyName, mappedNestedResults)); config(builder); return(this); }