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

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to do a full outer join in Linq?(如何在 Linq 中进行完整的外部联接?)
How do I group data in an ASP.NET MVC View?(如何在 ASP.NET MVC 视图中对数据进行分组?)
how to update the multiple rows at a time using linq to sql?(如何使用 linq to sql 一次更新多行?)
how to recognize similar words with difference in spelling(如何识别拼写不同的相似词)
C# Linq to SQL: How to express quot;CONVERT([...] AS INT)quot;?(C# Linq to SQL:如何表达“CONVERT([...] AS INT)?)
Why do quot;linq to sqlquot; queries starts with the FROM keyword unlike regular SQL queries?(为什么要“linq to sql与常规 SQL 查询不同,查询以 FROM 关键字开头?)