private string RemoveNodeAndChildrenCypher <T>(GraphInterfaces.IField field)
        {
            string nodeName = typeof(T).Name.ToLowerInvariant();

            return(_cypherBuilderFactory
                   .NewCypherBuilder()
                   .AddMatch(new[] { new Match {
                                         Pattern = $"(({nodeName[0]}:{nodeName}{{{field.Name}:'{field.Value}'}})-[*0..]->(x))"
                                     } })
                   .AddDetachDelete("x")
                   .ToString());
        }
        private string DeleteRelationshipCypher <A, B>(string relationShipName, GraphInterfaces.IField left, GraphInterfaces.IField right)
        {
            string objectAName = typeof(A).Name.ToLowerInvariant();
            string objectBName = typeof(B).Name.ToLowerInvariant();

            return(_cypherBuilderFactory
                   .NewCypherBuilder()
                   .AddMatch(new[] { new Match {
                                         Pattern = $"(a: {objectAName})-[r:{relationShipName}]->(b: {objectBName})"
                                     } })
                   .AddWhere($"a.{left.Name} = '{left.Value}' and b.{right.Name} = '{right.Value}'")
                   .AddDelete("r")
                   .ToString());
        }
        private string GetAllCypher <TNode>(GraphInterfaces.IField field, IEnumerable <string> relationships)
            where TNode : class
        {
            string node = typeof(TNode).Name.ToLowerInvariant();

            return(_cypherBuilderFactory.NewCypherBuilder()
                   .AddMatch(new[] { new Match {
                                         Pattern = $"(e:{node})"
                                     } })
                   .AddWhere($"e.{field.Name} = '{field.Value}'")
                   .AddMatch(new[] { new MatchWithAlias {
                                         Alias = "path", Pattern = $"(e) <-[{string.Join('|',relationships.Select(_ => $":{_}"))} *]-()"
                                     } })
                   .AddReturn(new[] { "e, path" })
                   .ToString());
        }
        private string GetCircularDependencyCypher <TNode>(string relationShip, GraphInterfaces.IField field)
        {
            string nodeName = typeof(TNode).Name.ToLowerInvariant();

            return(_cypherBuilderFactory
                   .NewCypherBuilder()
                   .AddMatch(new[] { new Match {
                                         Pattern = $"(e:{nodeName})"
                                     } })
                   .AddWhere($"SIZE((e)<-[:{relationShip}] - ()) <> 0")
                   .AddAnd($"SIZE(()<-[:{relationShip}] - (e)) <> 0")
                   .AddAnd($"e.{field.Name} = '{field.Value}'")
                   .AddMatch(new[] { new MatchWithAlias {
                                         Alias = "path", Pattern = $"(e) <-[:{relationShip} *]-(e)"
                                     } })
                   .AddReturn(new[] { "e, path" })
                   .ToString());
        }
        public async Task <IEnumerable <Entity <TNode> > > GetAllEntities <TNode>(GraphInterfaces.IField field, IEnumerable <string> relationships)
            where TNode : class
        {
            IAsyncSession session = AsyncSession();

            try
            {
                string         cypher  = GetAllCypher <TNode>(field, relationships);
                List <IRecord> records = await session.ReadTransactionAsync(tx => RunCypherWithResults(tx, cypher));

                return(records?.Select(_ => new Entity <TNode> {
                    Node = _[0].As <INode>().Properties.AsJson().AsPoco <TNode>(), Relationships = Transform(_[1].As <IPath>())
                }));
            }
            finally
            {
                await session.CloseAsync();
            }
        }
        public async Task DeleteRelationship <A, B>(string relationShipName, GraphInterfaces.IField left, GraphInterfaces.IField right)
        {
            string cypher = DeleteRelationshipCypher <A, B>(relationShipName, left, right);

            await ExecuteCypher(cypher);
        }
        public async Task DeleteNode <T>(GraphInterfaces.IField field)
        {
            string cypher = RemoveNodeCypher <T>(field.Name, field.Value);

            await ExecuteCypher(cypher);
        }