我有一个像这样的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; }
}
和这样的文件:
以下linq因selectmany而无效:
test = (from student in session.Query()
from eduhistory in student.CategoryAttributes["EducationHistory"]
where eduhistory["StartYear"] == "2009"
select student).ToList();
如何让所有学生参加StartYear == 2009?
答案 0 :(得分: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();
等等。
答案 1 :(得分:1)
这应该有效:
test = (from student in session.Query()
where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
select student).ToList();