public async Task ShouldThrowExceptionIfNullResult()
            {
                IStatementResultCursor result = null;
                var exception = await Record.ExceptionAsync(() => result.ToListAsync());

                exception.Should().BeOfType <ArgumentNullException>();
            }
            public async Task <int> AddEmployeesAsync(string companyName)
            {
                var session = Driver.Session();

                try
                {
                    var persons = await session.ReadTransactionAsync(async tx =>
                    {
                        IStatementResultCursor result = await tx.RunAsync("MATCH (a:Person) RETURN a.name AS name");
                        return(await result.ToListAsync());
                    });

                    return(persons.Sum(person => session.WriteTransactionAsync(async tx =>
                    {
                        await tx.RunAsync("MATCH (emp:Person {name: $person_name}) " +
                                          "MERGE (com:Company {name: $company_name}) " +
                                          "MERGE (emp)-[:WORKS_FOR]->(com)",
                                          new { person_name = person["name"].As <string>(), company_name = companyName });

                        return 1;
                    }).Result));
                }
                finally
                {
                    await session.CloseAsync();
                }
            }
Example #3
0
        public async Task <string> Read()
        {
            string result = string.Empty;

            using (ISession session = GlobalDatabaseContext.Driver.Session())
            {
                string query = "match (user:User {name:\"User\"}) return user.name as Name";
                await session.ReadTransactionAsync(async x =>
                {
                    IStatementResultCursor cursor = await x.RunAsync(query);
                    var tmp = await cursor.ToListAsync(c => {
                        return(c.To <string>("Name"));
                    });
                    result = tmp.FirstOrDefault();
                    query  = string.Empty;
                });

                return(result);
            }
        }