DocumentFramework.Tool
0.1.0-alpha
This is a prerelease version of DocumentFramework.Tool.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet tool install --global DocumentFramework.Tool --version 0.1.0-alpha
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local DocumentFramework.Tool --version 0.1.0-alpha
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=DocumentFramework.Tool&version=0.1.0-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package DocumentFramework.Tool --version 0.1.0-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Document Framework
A light weight ORM for mongo and dotnet.
Notable features
- EF style registration and usage
- Migrations
Usage
- Add a model
public class Foo
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Text { get; set; }
}
- Create a
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");
}
}
- Create a migration
public class SeedFoos : IMongoMigration
{
public string MigrationName => "20210420000000_Foos";
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" }
});
}
}
- Register Context and mongo database in the
ConfigureServices
method in yourStartup.cs
services
.AddMongoContext<BarMongoContext>()
.AddTransient<IMongoDatabase>()
- Sync migrations in the
Configure
method in yourStartup.cs
app.ApplicationServices
.GetRequiredService<BarMongoContext>()
.SyncMigrations();
- 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 | Versions 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.
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
0.1.1-alpha | 185 | 10/26/2021 |
0.1.0-alpha | 155 | 10/26/2021 |