Genel

C# MongoDB ORM Tool

Entity framework gibi orm araçlarını tüm db işlemlerinde arayan geliştiriciler için Mongodb tarafında kullanışlı bir kütüphane hazırlanmış.

//Bağlantı
await DB.InitAsync("bookshop","localhost");
//Insert
var dickens = new Author { Name = "Charles Dickens" };
  book.Author = dickens.ToDocument();
  await book.SaveAsync();
//Find
  var authors = await DB.Find<Author>().ManyAsync(a => a.Publisher == "Harper Collins");

  var eckhart = await DB.Queryable<Author>()
                        .Where(a => a.Name.Contains("Eckhart"))
                        .SingleOrDefaultAsync();

  var powerofnow = await genre.AllBooks
                              .ChildrenQueryable()
                              .Where(b => b.Title.Contains("Power"))
                              .SingleOrDefaultAsync();
//Update
await DB.Update<Book>()
          .Match(b => b.Title == "The Power Of Now")
          .Modify(b => b.Publisher, "New World Order")
          .Modify(b => b.ISBN, "SOMEISBNNUMBER")
          .ExecuteAsync();
//Delete
await book.DeleteAsync();
  await DB.DeleteAsync<Genre>("ID");
  await DB.DeleteAsync<Book>(b => b.Title == "The Power Of Now");

https://mongodb-entities.com/index.html