Example #1
0
        static async Task <string> Example5()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (actor:Person)
                    WITH actor
                    ORDER BY actor.born
                    LIMIT 2
                    MATCH (actor)-[:ACTED_IN]->(movie:Movie)
                    WITH actor, movie
                    ORDER BY movie.released DESC
                    WITH actor, collect(movie) AS movies
                    RETURN actor, head(movies) AS newestMovie");

                var actorWithMovies = (await cursor.ToListAsync())
                                      .Map((Person actor, Movie newestMovie) => new
                {
                    Actor = actor,
                    NewestMovie = newestMovie
                }).ToList();

                return actorWithMovies.Dump();
            }));
        }
Example #2
0
        static async Task <string> Example14()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (movie:Movie {released: $year})
                    RETURN movie", new { year = 1999 });

                var movies = await cursor.MapAsync <MovieEntity>();

                var matrix = movies.Single(p => p.title == "The Matrix");
                matrix.imdb = "tt0133093";

                var updateParams = new Neo4jParameters()
                                   .WithEntity("updatedMovie", matrix)
                                   .WithValue("nodeId", matrix.id);

                cursor = await session.RunAsync(@"
                    MATCH (movie)
                    WHERE id(movie) = $nodeId
                    SET movie = $updatedMovie
                    RETURN movie", updateParams);

                var updatedMovie = await cursor.MapSingleAsync <MovieEntity>();

                return updatedMovie.Dump();
            }));
        }
Example #3
0
        static async Task <string> Example12()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var movie = new IMDBMovie
                {
                    imdb = "tt0110912",
                    released = 1994,
                    tagline =
                        "The lives of two mob hitmen, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption.",
                    title = "Pulp Fiction"
                };

                var parameters = new Neo4jParameters()
                                 .WithEntity("newMovie", movie);

                var cursor = await session.RunAsync(@"
                    CREATE (movie:Movie $newMovie)
                    RETURN movie", parameters);

                var createdMovie = await cursor.MapSingleAsync <IMDBMovie>();

                return createdMovie.Dump();
            }));
        }
Example #4
0
 private static async Task DeleteBondMovies()
 {
     await Bolt.NewAsyncSession(async session =>
     {
         await session.RunAsync(Query.DeleteBond);
     });
 }
Example #5
0
 private static async Task LoadMovies()
 {
     await Bolt.NewAsyncSession(async session =>
     {
         await session.RunAsync(Query.CreateMovies);
     });
 }
Example #6
0
 private static async Task LoadBondMovies()
 {
     await Bolt.NewAsyncSession(async session =>
     {
         var queryParts = Query.CreateBond.Split(';');
         foreach (var queryPart in queryParts)
         {
             await session.RunAsync(queryPart);
         }
     });
 }
Example #7
0
        static async Task <string> Example8()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"RETURN { temporalValue: datetime() } as map");

                var customType = (await cursor.SingleAsync())
                                 .Map <Example8CustomType>();

                return customType.Dump();
            }));
        }
Example #8
0
        static async Task <string> Example3()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (person:Person)
                    RETURN person
                    LIMIT 1");

                var person = (await cursor.SingleAsync())
                             .Map <Person>();

                return person.Dump();
            }));
        }
Example #9
0
        static async Task <string> Example13()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var actorWithMovies = new Person
                {
                    name = "Samuel L. Jackson",
                    born = 1948,
                    MoviesActedIn = new List <Movie>
                    {
                        new Movie
                        {
                            released = 1994,
                            tagline =
                                "The lives of two mob hitmen, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption.",
                            title = "Pulp Fiction"
                        },
                        new Movie
                        {
                            released = 1996,
                            tagline =
                                "A woman suffering from amnesia begins to recover her memories after trouble from her past finds her again.",
                            title = "The Long Kiss Goodnight"
                        },
                        new Movie
                        {
                            released = 2000,
                            tagline =
                                " A man learns something extraordinary about himself after a devastating accident.",
                            title = "Unbreakable"
                        }
                    }
                };

                var parameters = new Neo4jParameters()
                                 .WithEntity("newActor", actorWithMovies)
                                 .WithEntities("newMovies", actorWithMovies.MoviesActedIn);

                await session.RunAsync(@"
                        CREATE (person:Person $newActor)
                        WITH person
                        UNWIND $newMovies AS newMovie
                        CREATE (person)-[:ACTED_IN]->(movie:Movie)
                        SET movie = newMovie", parameters);

                return string.Empty;
            }));
        }
Example #10
0
        private static async Task <string> Directors()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (people:People)-[r:DIRECTOR_OF]->(film:Film)
                    RETURN people, COLLECT(film)");

                var directedMovies = (await cursor
                                      .MapAsync((People people, IEnumerable <Film> films) => new
                {
                    Director = people.Name,
                    Time = films.Count()
                })).OrderByDescending(o => o.Time);

                return directedMovies.Dump();
            }));
        }
Example #11
0
        private static async Task <string> MoviesByActor()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (people:People)-[:AS_BOND_IN]->(film:Film)
                    RETURN people, COLLECT(film)");

                var moviesByActor = (await cursor
                                     .MapAsync((People people, IEnumerable <Film> films) => new
                {
                    Actor = people.Name,
                    BondMovies = films.Count()
                })).OrderByDescending(o => o.BondMovies);

                return moviesByActor.Dump();
            }));
        }
Example #12
0
        static async Task <string> Example2()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (movie:Movie)
                    RETURN movie
                    LIMIT 1");

                var output = new StringBuilder();
                foreach (var record in await cursor.ToListAsync())
                {
                    output.AppendLine(record.Values.Dump());
                }

                return output.ToString();
            }));
        }
Example #13
0
        static async Task <string> Example9()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var parameters = new Dictionary <string, object>
                {
                    { "imdb", "tt0133093" }
                };

                var cursor = await session.RunAsync(@"
                    MATCH (movie:Movie {title: 'The Matrix'})
                    SET movie.imdb = $imdb
                    RETURN movie", parameters);

                var updatedMovie = await cursor.MapSingleAsync <IMDBMovie>();

                return updatedMovie.Dump();
            }));
        }
Example #14
0
        static async Task <string> Example15()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (movie:Movie {released: $year})
                    RETURN movie", new { year = 1999 });

                var movies = await cursor.MapAsync <MovieEntity>();

                var matrix = movies.Single(p => p.title == "The Matrix");
                matrix.imdb = "tt0133093";

                await session.SetNodeAsync(matrix);

                var updatedMovie = await session.GetNodeAsync <MovieEntity>(matrix.id);

                return updatedMovie.Dump();
            }));
        }
Example #15
0
        static async Task <string> Example10()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var parameters = new Neo4jParameters
                {
                    { "titleSearch", "Top Gun" },
                    { "imdb", "tt0092099" }
                };

                var cursor = await session.RunAsync(@"
                    MATCH (movie:Movie {title: $titleSearch})
                    SET movie.imdb = $imdb
                    RETURN movie", parameters);

                var updatedMovie = await cursor.MapSingleAsync <IMDBMovie>();

                return updatedMovie.Dump();
            }));
        }
Example #16
0
        private static async Task <string> VehicleBrands()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (film:Film)-[:HAS_VEHICLE]->(vehicle:Vehicle)
                    RETURN DISTINCT vehicle.Brand AS Brand, 
                    count(vehicle.Model) AS Models, 
                    collect(DISTINCT film) AS Films");

                var vehicleBrands = (await cursor
                                     .MapAsync((string brand, int modelCount, IEnumerable <Film> films) => new
                {
                    Brand = brand,
                    Models = modelCount,
                    Movies = films.Select(f => f.Name)
                })).OrderByDescending(o => o.Models);

                return vehicleBrands.Dump();
            }));
        }
Example #17
0
        static async Task <string> Example4()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (actor:Person {name: 'Cuba Gooding Jr.'})-[:ACTED_IN]->(movie:Movie)
                    WITH actor, movie
                    ORDER BY movie.released
                    WITH actor, collect(movie) AS movies
                    RETURN actor, head(movies) AS firstMovie");

                var actorWithMovie = (await cursor.SingleAsync())
                                     .Map((Person actor, Movie firstMovie) => new
                {
                    Actor = actor,
                    FirstMovie = firstMovie
                });

                return actorWithMovie.Dump();
            }));
        }
Example #18
0
        private static async Task <string> Top3BoxOfficeMovies()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (film:Film) 
                    WITH film ORDER BY film.Box DESC 
                    RETURN film 
                    LIMIT 3");

                var boxOfficeFilms = (await cursor
                                      .MapAsync <Film>())
                                     .Select(f => new
                {
                    f.Name,
                    f.Year,
                    BoxOffice = f.Box
                });

                return boxOfficeFilms.Dump();
            }));
        }
Example #19
0
        private static async Task <string> MichelleYeohMovie()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (people:People)-[:IS_BOND_GIRL_IN]->(film:Film) 
                    WHERE people.Name=$Name
                    RETURN people, film", new
                {
                    Name = "Michelle Yeoh"
                });

                var michelleFilms = await cursor
                                    .MapAsync((People people, Film film) => new
                {
                    film.Year,
                    Title = film.Name,
                    people.Role
                });

                return michelleFilms.Dump();
            }));
        }
Example #20
0
        static async Task <string> Example6()
        {
            return(await Bolt.NewAsyncSession(async session =>
            {
                var cursor = await session.RunAsync(@"
                    MATCH (actor:Person {name: 'Cuba Gooding Jr.'})-[:ACTED_IN]->(movie:Movie)
                    WITH count(movie) as countOfMovies, actor.name as actorName, actor, COLLECT(movie) as movies
                    RETURN countOfMovies, actorName, actor, size(movies) > 0 as hasMovies, movies");

                var actorWithMovies = (await cursor.SingleAsync())
                                      .Map <int, string, Person, bool, List <Movie>, Example6Projection>(
                    (numOfMovies, actorName, person, hasMovies, movies) => new Example6Projection
                {
                    NumberOfMovies = numOfMovies,
                    ActorName = actorName,
                    Actor = person,
                    HasMovies = hasMovies,
                    Movies = movies
                });

                return actorWithMovies.Dump();
            }));
        }