Exemplo n.º 1
0
        /// <summary>
        ///     Store fields into the JSON entity structure.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="entityData">The entity being read.</param>
        /// <param name="entityJson">JSON for holding member data for the individual entity.</param>
        private void AppendFieldsToEntity(JsonQueryResult result, EntityData entityData,
                                          Dictionary <string, object> entityJson)
        {
            Dictionary <long, JsonMember> members = result.Members;

            // Visit fields
            foreach (FieldData field in entityData.Fields)
            {
                long fieldId = field.FieldId.Id;
                // Register the field member
                JsonMember member;
                if (members.TryGetValue(fieldId, out member))
                {
                    if (field.FieldId.Alias != null && member.Alias == null)
                    {
                        member.Alias = GetAliasString(field.FieldId);
                    }
                }
                else
                {
                    member = new JsonMember
                    {
                        Alias = GetAliasString(field.FieldId), DataType = DataTypeHelper.FromDatabaseType(field.Value.Type).ToString( )
                    };
                    members.Add(fieldId, member);
                }

                object value = field.Value.Value;

                // Ensure empty strings are represented as nulls - this is by design!
                if (value is string && (( string )value).Length == 0)
                {
                    value = null;
                }

                // Store the data in the entity
                entityJson[fieldId.ToString(CultureInfo.InvariantCulture)] = value;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Registers a 'member' entry for the relationship.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="rel">The relative.</param>
        private void RegisterRelationshipMember(JsonQueryResult result, RelationshipData rel)
        {
            Dictionary <long, JsonMember> members = result.Members;
            long relId = rel.RelationshipTypeId.Id;

            // Determine if there is an existing member registered for this relationship.
            // And create one if necessary.
            JsonMember member;

            if (!members.TryGetValue(relId, out member))
            {
                member = new JsonMember( );
                members.Add(relId, member);
            }

            // Then we ensure there is information for the member in the particular direction that we're interested in.
            JsonRelationshipMember relMember = rel.IsReverseActual ? member.Reverse : member.Forward;

            if (relMember == null)
            {
                relMember = new JsonRelationshipMember
                {
                    Alias = GetAliasString(rel.RelationshipTypeId), IsLookup = rel.IsLookup
                };
                if (rel.IsReverseActual)
                {
                    member.Reverse = relMember;
                }
                else
                {
                    member.Forward = relMember;
                }
            }
            else if (relMember.Alias == null && rel.RelationshipTypeId.Alias != null)
            {
                relMember.Alias = GetAliasString(rel.RelationshipTypeId);
            }
        }