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

3

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

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14