RavenDB: how to retrieve the top nodes in a nested collection?

邮差的信 提交于 2019-12-12 04:17:00

问题


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:


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



来源:https://stackoverflow.com/questions/34295426/ravendb-how-to-retrieve-the-top-nodes-in-a-nested-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!