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.
This should work:
test = (from student in session.Query()
where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
select student).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With