我将以下类的对象存储在ravendb数据库中:
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; }
}
感谢帖子(RavenDB:如何检索嵌套集合中的顶级节点?)我已经学会了如何使用session.Query从数据库中检索所有具有Name和Address分别设置为&#的城市的大陆34; aloma&#34;和&#34; 123&#34;。我想使用session.Advanced.DocumentQuery编写相同的查询。那么请你告诉我如何将以下查询转换为session.Advanced.DocumentQuery:var continents = session.Query()。Where(x =&gt; x.Countries.Any(country =&gt; country.Provinces.Any (p =&gt; p.Cities.Any(city =&gt; city.Name ==&#34; 123&#34;&amp;&amp; city.Address ==&#34; aloma&#34;)))。OfType ()。ToList();?
答案 0 :(得分:0)
注意,这可能不是最好的方法,但这是我知道的唯一方法。另外,请注意以下内容将在执行后创建索引。
var results = session.Advanced.DocumentQuery<Continent>().Where("Countries,Provinces,Cities,Name: 123 AND Countries,Provinces,Cities,Address: aloma").ToList();
使用的模型结构:
public class Continent
{
public string Id { get; set; }
public string Name { get; set; }
public List<Country> Countries { get; set; }
}
public class Country
{
public string Name { get; set; }
public List<Province> Provinces { get; set; }
}
public class Province
{
public string Name { get; set; }
public List<City> Cities { get; set; }
}
public class City
{
public string Name { get; set; }
public string Address { get; set; }
}