Advertisement
Guest User

raven dictionary test

a guest
May 12th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Raven.Client.Document;
  7. namespace RavenDynamicTest
  8. {
  9.     class Program
  10.     {
  11.         public class Student
  12.         {
  13.             public string Id { get; set; }
  14.             public string TopLevelProperty { get; set; }
  15.             public Dictionary<string, string> Attributes { get; set; }
  16.             public Dictionary<string, List<Dictionary<string, string>>> CategoryAttributes { get; set; }
  17.         }
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             var store = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "SchoolDb" };
  22.             store.Initialize();
  23.  
  24.             //creation
  25.             using (var session = store.OpenSession())
  26.             {
  27.                 //now the student:
  28.                 var student = new Student();
  29.                 //Top level Property
  30.                 student.TopLevelProperty = "toplevel";
  31.                 //Simple attributes
  32.                 student.Attributes = new Dictionary<string, string>();
  33.                 student.Attributes["second"] = "second";
  34.                 //CategoryAttributes
  35.                 student.CategoryAttributes = new Dictionary<string, List<Dictionary<string, string>>>();
  36.                 student.CategoryAttributes["EducationHistory"] = new List<Dictionary<string, string>>();
  37.  
  38.                 var dict = new Dictionary<string, string>();
  39.                 dict["StartYear"] = "2009";
  40.                 student.CategoryAttributes["EducationHistory"].Add(dict);
  41.                 session.Store(student);
  42.                 session.SaveChanges();
  43.             }
  44.  
  45.             using (var session = store.OpenSession())
  46.             {
  47.                 var test = (from student in session.Query<Student>()
  48.                             where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"] == "2009")
  49.                             select student).ToList();
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement