示例#1
0
        public async void TestInsertRelation()
        {
            var country = new Country()
            {
                CountryID = "555", CountryName = "NOM COUNTRY"
            };
            var city = new City()
            {
                CityId = "5555", CityName = "NOM CITY"
            };

            country.Cities = new List <City>()
            {
                city
            };
            var context = new NeoContext(Driver);
            await context.InsertNode <Country>(country);

            await context.InsertNode <City>(city);

            var resultRelEx = await context.InsertRelation <EXISTS_IN>(
                "MATCH (n:Country { CountryID: '555' }) " +
                "MATCH (c:City { CityId: '5555' })", "c", "n", new EXISTS_IN());

            var resultCountry = await context.QueryDefaultIncludeable <Country, City>("MATCH (n:Country { CountryID: '555' })<-[e:EXISTS_IN]-(c:City) return n,c",
                                                                                      (country, city) =>
            {
                country.Cities = new List <City>()
                {
                    city
                };
                return(country);
            }
                                                                                      );

            Assert.True(resultRelEx.QueryType == Neo4j.Driver.QueryType.WriteOnly);
            Assert.True(IsEqual(country, resultCountry));
            await context.ExecuteQuery("MATCH (n:Country { CountryID: '555' }) DETACH DELETE n");

            await context.ExecuteQuery("MATCH (n:City { CityId: '5555' }) DETACH DELETE n");
        }