Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Created November 16, 2011 12:12
Show Gist options
  • Save mattwarren/1369941 to your computer and use it in GitHub Desktop.
Save mattwarren/1369941 to your computer and use it in GitHub Desktop.
Querying dictionaries in RavenDB
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; }
}
@sachinchakole
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment