DocumentFramework 0.1.1-alpha

This is a prerelease version of DocumentFramework.
dotnet add package DocumentFramework --version 0.1.1-alpha
NuGet\Install-Package DocumentFramework -Version 0.1.1-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DocumentFramework" Version="0.1.1-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DocumentFramework --version 0.1.1-alpha
#r "nuget: DocumentFramework, 0.1.1-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DocumentFramework as a Cake Addin
#addin nuget:?package=DocumentFramework&version=0.1.1-alpha&prerelease

// Install DocumentFramework as a Cake Tool
#tool nuget:?package=DocumentFramework&version=0.1.1-alpha&prerelease

Document Framework

.NET Package .NET Tool Nuget

A light weight ORM for mongo and dotnet.

Notable features

  • EF style registration and usage
  • Migrations

Usage

  1. Add a model
public class Foo
{
  [BsonId]
  [BsonRepresentation(BsonType.ObjectId)]
  public string Id { get; set; }
  public string Text { get; set; }
}
  1. Create a MongoContext
dotnet df dbcontext scaffold -c BarMongoContext
  1. Add a collection for your model to you MongoContext
public class BarMongoContext : MongoContext
{
  public readonly IMongoCollection<Foo> Foos;

  public BarMongoContext(IMongoDatabase database, IEnumerable<IMongoMigration> migrations, ILogger<MongoContext> logger)
    : base(migrations, database, logger)
  {
    Foos = GetOrAddCollection<Foo>("foos"); // Add this line in you generated mongo context
  }
}
  1. Create a migration
dotnet df migrations add SeedFoos
  1. Implement the MigrationForward and MigrateBackward methods in your new migration
public class SeedFoos : IMongoMigration
{
  public string MigrationName => "20210420000000_SeedFoos";
  private readonly IMongoDatabase _database;

  public SeedFoos(IMongoDatabase database)
  {
    _database = database;
  }

  public void MigrateForward()
  {
    var fooCollection = _database.GetCollection<Foo>("foos");

    fooCollection.InsertMany(new Foo[] { 
        new Foo { Text = "document-1" }, 
        new Foo { Text = "document-2" }
    });
  }

  public void MigrateBackward()
  {
    throw new NotImplementedException();
  }
}
  1. Register Context and mongo database in the ConfigureServices method in your Startup.cs
services
    .AddMongoContext<BarMongoContext>()
    .AddTransient<IMongoDatabase>()
  1. Sync migrations in the Configure method in your Startup.cs
app.ApplicationServices
        .GetRequiredService<BarMongoContext>()
        .SyncMigrations();
  1. Use the Mongo context to query collections
public class SomeService
{
    private readonly BarMongoContext _context;

    public SomeService(BarMongoContext context)
    {
        _context = context;
    }

    public IEnumerable<Foo> GetSomeFooStuff(string text) 
    {
        _context.Foos.Find(f => f.Text == text).ToEnumerable();
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1-alpha 174 10/26/2021
0.1.0-alpha 144 10/26/2021
0.0.7-alpha 160 10/14/2021
0.0.6-alpha 167 10/12/2021
0.0.5-alpha 148 10/12/2021
0.0.4-alpha 136 10/11/2021
0.0.3-alpha 140 10/11/2021
0.0.2-alpha 141 10/11/2021
0.0.1-alpha 166 10/11/2021