Created
September 27, 2010 17:00
-
-
Save CoreyKaylor/599372 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
MongoConfiguration.Initialize(c => c.AddMap<PersonMap>()); | |
using (var db = Mongo.Create("mongodb://localhost/test")) | |
{ | |
var people = db.GetCollection<Person>(); | |
people.Save(new Person { FirstName = "myfirst", LastName = "mylast" }); | |
var person = (from p in people.AsQueryable() | |
where p.FirstName == "myfirst" | |
select p).Single(); | |
Console.WriteLine(person.FirstName + " " + person.LastName); | |
} |
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 Person | |
{ | |
public Person() | |
{ | |
Id = Guid.NewGuid(); | |
} | |
public Guid Id { get; set; } | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public bool Equals(Person other) | |
{ | |
if (ReferenceEquals(null, other)) return false; | |
if (ReferenceEquals(this, other)) return true; | |
return other.Id.Equals(Id); | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (ReferenceEquals(this, obj)) return true; | |
if (obj.GetType() != typeof (Person)) return false; | |
return Equals((Person) obj); | |
} | |
public override int GetHashCode() | |
{ | |
return Id.GetHashCode(); | |
} | |
} | |
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 PersonMap : MongoConfigurationMap | |
{ | |
public PersonMap() | |
{ | |
For<Person>(config => config.IdIs(p => p.Id)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment