Workaround for selectmany in ravendb using api client

I have a ravendb class such as:


        public class Student
        {
            public string Id { get; set; }
            public string TopLevelProperty { get; set; }
            public Dictionary&ltstring, string&gt Attributes { get; set; }
            public Dictionary&ltstring,List&ltDictionary&ltstring, string&gt&gt&gt CategoryAttributes { get; set; }
        }

and such a document:
enter image description here

The following linq will not work due to 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?

+5
source share
2 answers

It does:


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

Note the comma, not the dot after the EducationHistory. This indicates that we are browsing the list to find a property in one of the elements named StartYear. If I wanted more than:


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

etc.

+3
source

This should work:

test = (from student in session.Query()
       where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
       select student).ToList();
+1
source

All Articles