本文介绍了使用客户端 api 在 ravendb 中解决 selectmany的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的 ravendb 类:

公开课学生{公共字符串 ID { 获取;放;}公共字符串 TopLevelProperty { 获取;放;}公共字典属性{获取;放;}公共字典<string,List<Dictionary<string,string>>> CategoryAttributes { get;放;}}

和这样的文档:

由于选择多,以下 linq 将不起作用:

test = (来自 session.Query() 中的学生来自 student.CategoryAttributes["EducationHistory"] 中的 eduhistory其中 eduhistory["StartYear"] == "2009"选择学生).ToList();

我怎样才能让所有学生都在 StartYear == 2009?

解决方案

这样做:

测试 = session.Advanced.LuceneQuery().Where("CategoryAttributes.EducationHistory,StartYear:2009").ToList();

注意 EducationHistory 后面的逗号而不是点.这表明我们正在查看列表以在名为 StartYear 的项目之一中查找属性.如果我想要大于:

测试 = session.Advanced.LuceneQuery().Where("CategoryAttributes.EducationHistory,StartYear:[2009 TO null]").ToList();

等等等等

I have a ravendb class like such:


        public class Student
        {
            public string Id { get; set; }
            public string TopLevelProperty { get; set; }
            public Dictionary<string, string> Attributes { get; set; }
            public Dictionary<string,List<Dictionary<string, string>>> CategoryAttributes { get; set; }
        }

and a document like so:

The following linq will not work due to a selectmany:


                test = (from student in session.Query()
                        from eduhistory in student.CategoryAttributes["EducationHistory"]
                        where eduhistory["StartYear"] == "2009"
                              select student).ToList();

How can I get all students where StartYear == 2009?

解决方案

This does it :


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:2009")
            .ToList();

Notice the comma rather than a dot after EducationHistory. This indicates that we are looking at the list to find a property in one of the items named StartYear. If I wanted greater than :


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:[2009 TO null]")
            .ToList();

etc etc.

这篇关于使用客户端 api 在 ravendb 中解决 selectmany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 23:53