示例#1
0
        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();
            }
        }
示例#2
0
 internal void WriteJsonObject(MappedObject mappedObject, JsonTextWriter jsonWriter, IDictionary <string, object> currentRow, RowSet rowSet, List <string> fieldNameList, ParentObject parent, IDictionary <string, object> context)
 {
     jsonWriter.WriteStartObject();
     foreach (var prop in mappedObject.MappedPropertyList)
     {
         if (prop.GetValidQuery() != null)
         {
             var localParent = new ParentObject(parent, currentRow, prop);
             WriteQueryResults(prop.GetValidQuery(), jsonWriter, localParent, context, prop);
         }
         else if (prop.MappedObject != null)
         {
             jsonWriter.WritePropertyName(prop.TargetPropertyName);
             WriteJsonObject(prop.MappedObject, jsonWriter, currentRow, rowSet, fieldNameList, parent, context);
         }
         else if (prop.MappedNestedResults != null)
         {
             WriteNestedResult(prop, prop.MappedNestedResults, jsonWriter, rowSet, fieldNameList, parent, context);
         }
         else if (prop.ValueResolver != null)
         {
             WriteCustomResolvedValue(prop, jsonWriter, currentRow, context);
         }
         else
         {
             WriteColumnValue(prop, jsonWriter, currentRow, fieldNameList);
             WriteStaticValue(prop, jsonWriter);
         }
     }
     jsonWriter.WriteEndObject();
 }