using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;
namespace RavenDynamicTest
{
class Program
{
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; }
}
static void Main(string[] args)
{
var store = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "SchoolDb" };
store.Initialize();
//creation
using (var session = store.OpenSession())
{
//now the student:
var student = new Student();
//Top level Property
student.TopLevelProperty = "toplevel";
//Simple attributes
student.Attributes = new Dictionary<string, string>();
student.Attributes["second"] = "second";
//CategoryAttributes
student.CategoryAttributes = new Dictionary<string, List<Dictionary<string, string>>>();
student.CategoryAttributes["EducationHistory"] = new List<Dictionary<string, string>>();
var dict = new Dictionary<string, string>();
dict["StartYear"] = "2009";
student.CategoryAttributes["EducationHistory"].Add(dict);
session.Store(student);
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var test = (from student in session.Query<Student>()
where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"] == "2009")
select student).ToList();
}
}
}
}