2011-05-12 62 views
5

我有一个ravendb类像这样:解决方法在ravendb的SelectMany使用客户端API

 

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

和像这样的文件:
enter image description here

下LINQ将无法正常工作因的SelectMany :

 

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

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

回答

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(); 
 

等等等等

+0

对于像我使用的情况下( “CategoryAttributes.EducationHistory,StartYear:* 200 *”) – basarat 2011-05-12 10:20:18

1

这应该工作:

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

我收到错误:无法投入'System.Linq.Expressions.TypedParameterExpression'类型的对象来键入'System.Linq.Expressions.MemberExpression'。 – basarat 2011-05-12 10:18:00

+0

我正在使用一个内部修复的地方:http://stackoverflow.com/q/5800685/390330但是我在这个查询中得到了同样的错误。 – basarat 2011-05-12 10:22:31

+0

您可以在这里获得完整的测试代码:http://pastebin.com/c6HDjQcS – basarat 2011-05-12 10:27:06