Beispiel #1
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);
            }