5

我有一个像这样的 ravendb 类:


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

和这样的文件:
在此处输入图像描述

由于 selectmany,以下 linq 将无法工作:


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

如何让 StartYear == 2009 的所有学生?

4

2 回答 2

3

这样做:


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

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


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

等等等等

于 2011-05-12T06:06:30.117 回答
1

这应该有效:

test = (from student in session.Query()
       where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
       select student).ToList();
于 2011-05-12T07:13:47.350 回答