Created
November 16, 2011 12:12
-
-
Save mattwarren/1369941 to your computer and use it in GitHub Desktop.
Querying dictionaries in RavenDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void DictionaryTest() | |
{ | |
var store = new EmbeddableDocumentStore | |
{ | |
RunInMemory = true | |
}; | |
store.Configuration.TempIndexPromotionMinimumQueryCount = 1; | |
store.Initialize(); | |
var entry1 = new ClassWithDictionary { Name = "With test", Dictionary = new Dictionary<string, string> { { "test", "value" } } }; | |
var entry2 = new ClassWithDictionary { Name = "Without test", Dictionary = new Dictionary<string, string> { { "nottest", "value" } } }; | |
var entry3 = new ClassWithDictionary { Name = "Empty" }; //empty dictionary | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(entry1); | |
session.Store(entry2); | |
session.Store(entry3); | |
session.SaveChanges(); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var rawQuery = session.Advanced.LuceneQuery<ClassWithDictionary>() | |
.WaitForNonStaleResultsAsOfNow() | |
.OpenSubclause() | |
.Where("Dictionary,Key:*") | |
.AndAlso() | |
.Not | |
.WhereEquals("Dictionary,Key", "test") | |
.CloseSubclause() | |
.OrElse() | |
.WhereEquals("Dictionary", @"{}"); | |
Console.WriteLine(rawQuery.ToString()); | |
var results = rawQuery.ToList(); | |
Console.WriteLine(results.Count + ", " + String.Join(", ", results.Select(x => x.Name))); | |
} | |
} | |
public class ClassWithDictionary | |
{ | |
public ClassWithDictionary() | |
{ | |
Dictionary = new Dictionary<string, string>(); | |
} | |
public Dictionary<string, string> Dictionary { get; set; } | |
public string Name { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey hi,
In My application, I want to create dictionary type document in ravendb using CheckBoxListFor
Now the My Question is how to store selectedListItem in dictionary?
Can you help me?