具有自定义字段名称的RavenDB查询索引 [英] RavenDB query index with custom fields names

查看:67
本文介绍了具有自定义字段名称的RavenDB查询索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RavenDB中收集了文档Message.定义:

I have collection of documents Message in RavenDB. Definition:

class Message
{
    string Content;
    Tag[] Tags;
}

class Tag
{
    string Value;
}

我有索引:

from doc in docs.Messages
from docTagsItem in (IEnumerable<dynamic>)doc.Tags
select new { Content = doc.Content, TagsValue = docTagsItem.Value }

在这里,我们有一个名称为TagsValue的字段,它不是Message类的一部分,这就是为什么我不能使用

Here we have field with name TagsValue which isn't part of class Message, that's why i can't using

Session.Query<Message>(indexName).Where(m=>m.TagsValue==tagValue)

如何通过TagValue从.NET查询此索引?我应该使用Advanced.LuceneQuery吗?

How should query this index from .NET by TagValue? Should i use Advanced.LuceneQuery?

推荐答案

由于使用Linq,因此需要创建一个具有该属性的类型来查询该类型,或者可以使用Lucene API.

Because you use Linq you need to create a type with that property to query that, or you can use Lucene API.

请注意,您实际上并不需要像使用静态索引那样进行查询,而可以仅使用动态索引和纯linq进行查询.

Note that you don't actually need to make a query like that using a static index, you can do that using just dynamic indexes and pure linq.

这篇关于具有自定义字段名称的RavenDB查询索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆