RavenDB: how to retrieve the top nodes in a nested

2019-09-11 06:52发布

I stored the objects of the following classes in a ravendb database:

public class Continent
    {
        public string Name { get; set; }
        public List<Country> Countries{ get; set; }
    }

public class Countries
    {
        public string Name { get; set; }
        public List<Province> Provinces{ get; set; }
    }

public class Province
    {
        public string Name { get; set; }
        public List<Province> Cities { get; set; }
    }

public class City
    {
        public string Name { get; set; }
        public string Address   { get; set; }
    }

How can I retrieve from the database all the continents having cities with Name and Address respectively set to "aloma" and "123"?

1条回答
放荡不羁爱自由
2楼-- · 2019-09-11 07:16

You can do that using the following query:

var continents = session.Query() .Where(c=>x.Countries.Any(country => country.Provinces.Any(p=>p.Cities.Any(city => city.Name == "123" && city.Address == "aloma"))).ToList();

查看更多
登录 后发表回答