Skip to content

mingditts/MongoIce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoIce

An entity framework-like library for MongoDB

Features

This library allows to create collections and indexes automatically based on a context decorated with some entity framework-like attributes. It allows also some additional helpers like collections cleanup. It's work in progress!

Usage

Model definition and description:

public class Comment
{
  [BsonId]
  [BsonRepresentation(BsonType.ObjectId)]
  public string Id { get; set; }

  [IndexDescriptor(IndexType.Ascending, true, false, false)]
  public long Timestamp { get; set; }

  public string AuthorName { get; set; }

  public string Content { get; set; }
}

public class MongoContext : BaseDocumentContext
{
  /// <summary>
  /// Comment collection
  /// </summary>
  [CollectionDescriptor("Comments", typeof(Comment))]
  public IMongoCollection<Comment> Comments { get; set; }

  public MongoContext(string serverUrl, string databaseName) : base(serverUrl, databaseName)
  {

  }

  public override void CreateIndexes()
  {
    base.Database.CreateIndex<Comment>(this.Comments);
  }
}

Context usage:

using (var context = new MongoContext("mongodb://localhost:27017", "MongoIceTestDatabase"))
{
  // perform all collection specific operation using linq and mongodb features
  
  context.Comments.DeleteMany(x => x.Id != null);
}

About

An entity framework-like library for MongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages