Beispiel #1
0
            void AddToPropertyCache(string propertyName, Type type)
            {
                var entityPropertyNames = new EntityReturnColumns(propertyName);

                _propertyCache.Add(propertyName, Array.IndexOf(_columns, propertyName));

                if (!typeof(IGraphEntity).IsAssignableFrom(type))
                {
                    return;
                }
                if (_columns.Contains(entityPropertyNames.IdPropertyName))
                {
                    _propertyCache.Add(entityPropertyNames.IdPropertyName, Array.IndexOf(_columns, entityPropertyNames.IdPropertyName));
                }
                if (type == typeof(Relationship))
                {
                    if (_columns.Contains(entityPropertyNames.TypePropertyName))
                    {
                        _propertyCache.Add(entityPropertyNames.TypePropertyName, Array.IndexOf(_columns, entityPropertyNames.TypePropertyName));
                    }
                }
                if (type != typeof(Node))
                {
                    return;
                }
                if (_columns.Contains(entityPropertyNames.LabelsPropertyName))
                {
                    _propertyCache.Add(entityPropertyNames.LabelsPropertyName, Array.IndexOf(_columns, entityPropertyNames.LabelsPropertyName));
                }
            }
Beispiel #2
0
            private IGraphEntity LoadGraphEntity(string propertyName, JToken record, Dictionary <string, object> itemproperties,
                                                 Type propertyType)
            {
                IGraphEntity graphEntity         = null;
                var          entityPropertyNames = new EntityReturnColumns(propertyName);

                AssertNecesaryColumnForType(entityPropertyNames.IdPropertyName, typeof(IGraphEntity));

                var recordIsArray = record.GetType().IsAssignableFrom(typeof(JArray));
                var entityId      = recordIsArray
                    ? record[_propertyCache[entityPropertyNames.IdPropertyName]].Value <long>() :
                                    record["row"][_propertyCache[entityPropertyNames.IdPropertyName]].Value <long>();

                if (_cache.Contains(entityId, propertyType))
                {
                    graphEntity = _cache.GetEntity(entityId, propertyType);
                }
                else
                {
                    itemproperties.Add("id", entityId);

                    AssertNecesaryColumnForType(entityPropertyNames.PropertiesPropertyName, typeof(IGraphEntity));
                    var entityProperties =
                        recordIsArray
                            ? record[_propertyCache[entityPropertyNames.PropertiesPropertyName]]
                        .ToObject <Dictionary <string, object> >() :
                        record["row"][_propertyCache[entityPropertyNames.PropertiesPropertyName]].ToObject <Dictionary <string, object> >();
                    itemproperties.Add("properties", entityProperties);

                    if (typeof(Node).IsAssignableFrom(propertyType))
                    {
                        AssertNecesaryColumnForType(entityPropertyNames.LabelsPropertyName, typeof(Node));
                        var labels = entityProperties.Keys.ToArray();
                        itemproperties.Add("labels", labels);
                    }
                    else
                    {
                        AssertNecesaryColumnForType(entityPropertyNames.TypePropertyName,
                                                    typeof(Relationship));
                        var relType = recordIsArray ?
                                      record[_propertyCache[entityPropertyNames.TypePropertyName]].ToObject <string>() :
                                      record["row"][_propertyCache[entityPropertyNames.TypePropertyName]].ToObject <string>();
                        itemproperties.Add("type", relType);
                    }

                    graphEntity = (IGraphEntity)HydrateWithCtr(itemproperties, propertyType);
                    _cache.CacheEntity(graphEntity);
                }
                return(graphEntity);
            }