RavenDB:如何在孙子上写查询?

时间:2015-12-21 02:50:25

标签: c# nested ravendb hierarchy

鉴于以下C#代码,我正在尝试检索所有拥有城市包括的省份的大陆:

  1. 一个名称和地址分别设置为" Aloma"和" 123"和
  2. 另一个名称和地址分别设置为" Hemane"和" 435"。
  3. 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; }
    }
    

    我曾尝试使用下面的查询,但它似乎不起作用。你能帮我吗?

    Expression<Func<Province, bool>> matchCities = rec =>
          (rec.Cities.Count(fi => fi.Name == "Aloma" && fi.Address== "123") > 0)
            && (rec.Cities.Count(fj => fj.Name == "Hemane" && fj.Address== "435") > 0);
    
    Func<Province, bool> funcMatchCities= matchCities.Compile();
    
    var results3 = session.Query<Continent>()
                          .Where(top => top.Countries.Any(ta => ta.Province.Any(
                                      rec => funcMatchCities(rec))))
                          .OfType<Continent>()
                          .ToList();
    

0 个答案:

没有答案