Created
May 24, 2010 23:38
-
-
Save atheken/412568 to your computer and use it in GitHub Desktop.
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
public class Widget | |
{ | |
public ObjectId Id {get;set;} | |
public String Color {get;set;} | |
public double Price {get;set;} | |
public DateTime ReleaseDate {get;set;} | |
public IEnumerable Reviews {get;set;} | |
} | |
//Next, spool up a connection to your database | |
//(The DB doesn't have to exist yet, but MongoDB DOES need to be running) | |
using(var db = Mongo.Create("mongo://localhost/ProductDB") | |
{ | |
//Get a reference to the collection in which we want to | |
//store our Widgets (doesn't have to exist yet.) | |
var widgets = db.GetCollection(); | |
//create a widget instance. | |
var topSellingWidget = new Widget{ Id = ObjectId.NewObjectId(), Color = "Red", Price = 39.95, | |
ReleaseDate = DateTime.Now, Reviews = Enumerable.Empty() }; | |
//now, save the instance | |
widgets.Save(topSellingWidget); | |
//lastly, retrieve it from the DB. | |
var hydratedTopSellingWidgetFromDB = widgets.FindOne(new {Color = "Red",Price = 39.95}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment