public bool HasEdge(Attributes.Edge edge, GraphObject from, GraphObject to) { bool hasEdge; string findEdgeQuery = $"g.E().hasLabel('{edge.EdgeName}').has('_vertexId', '{ from.GraphKey }').has('_sink', '{to.GraphKey}').count()"; FeedResponse <dynamic> reponse = ExecuteCommandQueryDynamic(findEdgeQuery); hasEdge = Convert.ToInt32(reponse.First()) > 0; return(hasEdge); }
private void CreateRelationIfNotExists(GraphObject from, Attributes.Edge att, GraphObject to) { object genericRepository; genericRepository = GetGenericRepository(to.GetType()); genericRepository.GetType().GetMethod("Add").Invoke(genericRepository, new object[] { to, true }); if (!HasEdge(att, from, to)) { CreateEdge(from, to, att); } }
public void CreateEdge(GraphObject from, GraphObject to, Attributes.Edge EdgeAttribute) { string addEdge = $"g.V('{from.GraphKey}').addE('{EdgeAttribute.EdgeName}').to(g.V('{to.GraphKey}'))", valueToString = string.Empty; object valueToObject = null; if (!EdgeAttribute.IgnoreEdgeProperties) { Attribute edgeAtt; foreach (PropertyInfo prop in to.GetType().GetProperties()) { edgeAtt = prop.GetCustomAttribute(typeof(EdgeProperty)); if (edgeAtt != null) { if (prop.PropertyType.BaseType == typeof(Enum)) { addEdge += $".property(\"{prop.Name}\", {(int)prop.GetValue(to)})"; } else if (prop.PropertyType == typeof(Int32)) { addEdge += $".property(\"{prop.Name}\", {prop.GetValue(to)})"; } else if (prop.PropertyType == typeof(DateTime)) { addEdge += $".property(\"{prop.Name}\", \"{((DateTime)prop.GetValue(to)).ToString()}\")"; } else { valueToObject = prop.GetValue(to); if (valueToObject != null) { valueToString = valueToObject.ToString().Replace("'", "’"); addEdge += $".property(\"{prop.Name}\", \"{valueToString}\")"; } else { addEdge += $".property(\"{prop.Name}\", \"{valueToObject}\")"; } } } } } ExecuteCommandEdge(addEdge); }