RavenDB:如何将 session.Query 转换为 session.Advanced.Do

RavenDB: how to transform a session.Query into a session.Advanced.DocumentQuery?(RavenDB:如何将 session.Query 转换为 session.Advanced.DocumentQuery?)

本文介绍了RavenDB:如何将 session.Query 转换为 session.Advanced.DocumentQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下类的对象存储在 ravendb 数据库中:

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; }
}

感谢一篇帖子(RavenDB:如何检索嵌套集合中的顶级节点?)我已经学会了如何使用 session.Query 从数据库中检索所有具有分别将 Name 和 Address 设置为aloma"的城市的大陆"和123".我想使用 session.Advanced.DocumentQuery 编写相同的查询.那么你能告诉我如何将以下查询转换为 session.Advanced.DocumentQuery: var continents = session.Query() .Where(x=>x.Countries.Any(country => country.Provinces.Any(p)=>p.Cities.Any(city => city.Name == "123" && city.Address == "aloma"))).OfType().ToList(); ?

Thanks to a post (RavenDB: how to retrieve the top nodes in a nested collection?) I have learned how to use session.Query to retrieve from the database all the continents having cities with Name and Address respectively set to "aloma" and "123". I would like to write the same query using session.Advanced.DocumentQuery. So can you please tell me how to transform the following query into a session.Advanced.DocumentQuery: var continents = session.Query() .Where(x=>x.Countries.Any(country => country.Provinces.Any(p=>p.Cities.Any(city => city.Name == "123" && city.Address == "aloma"))).OfType().ToList(); ?

推荐答案

注意,这可能不是最好的方法,但这是我知道的唯一方法.另外,请注意以下内容将在执行后创建索引.

Note, this is probably not the best way to do this but it's the only way I know how. Also, note the following will create an index once executed.

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; }
}

这篇关于RavenDB:如何将 session.Query 转换为 session.Advanced.DocumentQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:RavenDB:如何将 session.Query 转换为 session.Advanced.Do

基础教程推荐