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"?
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();