Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying a Dictionary with RavenDb

Tags:

ravendb

I have a class defined as:

public class Student
{
    public string Id { get; set; }
    public IDictionary<string, string> Attributes { get; set; }
}

based on the discussion I found here : http://groups.google.com/group/ravendb/browse_thread/thread/88ea52620021ed6c?pli=1

I can store an instance quite easily as :

//creation
using (var session = store.OpenSession())
{               
    //now the student:
    var student = new Student();
    student.Attributes = new Dictionary<string, string>();

    student.Attributes["NIC"] = "studentsNICnumberGoesHere";               
    session.Store(student);
    session.SaveChanges();
}

However when I query it as below:

//Testing query on attribute
using (var session = store.OpenSession())
{
    var result = from student in session.Query<Student>()
                 where
                     student.Attributes["NIC"] == "studentsNICnumberGoesHere"
                  select student;

    var test = result.ToList();                
}           

I get the error "'System.Linq.Expressions.InstanceMethodCallExpressionN' to type 'System.Linq.Expressions.MemberExpression'." as shown:

enter image description here How can I query based on a key in the dictionary?

like image 229
basarat Avatar asked Apr 27 '11 07:04

basarat


1 Answers

This is a bug, it is fixed now. Will be out in the next build, in about two hours

like image 191
Ayende Rahien Avatar answered Nov 01 '22 14:11

Ayende Rahien