Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created August 19, 2010 16:14
Show Gist options
  • Save mikeobrien/538255 to your computer and use it in GitHub Desktop.
Save mikeobrien/538255 to your computer and use it in GitHub Desktop.
using (var mongo = Mongo.Create("mongodb://user:password@localhost/Test"))
{
// Some strongly typed filter, I want a document with a number of 2
Expression<Func<User, bool>> filterExpression = u => u.Number == 2;
// A NoRM specific object, not important
var filter = new Expando();
// I need to pull the name "Number" and the value 2
// and programatically pass it to the NoRM expando object.
// IE: filter.Set("Number", 2);
// This is psuedocode here of course:
foreach (var filter in filterExpression.Body)
filter.Set(filter.Name, filter.Value);
// NoRM specific, not important
var user = mongo.GetCollection<User>().FindOne(filter);
Console.WriteLine(user != null ? user.Name : "Nothing found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment