Imato.MongoDb.Repository 1.0.1

dotnet add package Imato.MongoDb.Repository --version 1.0.1
NuGet\Install-Package Imato.MongoDb.Repository -Version 1.0.1
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="Imato.MongoDb.Repository" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Imato.MongoDb.Repository --version 1.0.1
#r "nuget: Imato.MongoDb.Repository, 1.0.1"
#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 Imato.MongoDb.Repository as a Cake Addin
#addin nuget:?package=Imato.MongoDb.Repository&version=1.0.1

// Install Imato.MongoDb.Repository as a Cake Tool
#tool nuget:?package=Imato.MongoDb.Repository&version=1.0.1

Imato.MongoDb.Repository

Generic MongoDb repository

How to use id

Add reference

using Imato.MongoDb.Repository;

Configure DB

var db = new MongoDb();
db.Configure(new MongoConfiguration
{
    DataBase = "testDb"
});

Define type for repository


public class TestEntity : IEntity
{
    public string Id { get; set; } = string.Empty;
    [WithIndex]
    public string Name { get; set; } = string.Empty;
    public DateTime Date { get; set; }
    public int Count { get; set; }
}

// Or use Base type

public class TestEntity : BaseEintity
{
    public DateTime Date { get; set; }
    public int Count { get; set; }

    public TestEntity Copy()
    {
        return (TestEntity)MemberwiseClone();
    }
}

Create and use repository

var repository = db.GetRepository<TestEntity>();

var ne = await repository.CreateAsync(new TestEntity
            {
                Name = "Test entry 1",
                Date = DateTime.Now,
                Count = 1
            });

var result = await repository.FindAsync(x => x.Id == ne.Id);

await repository.DeleteAsync(result);

Save app parameters

// Save new parameter
var app = new AppName();
await db.SetParameterAsync(app);
// Load from DB
var dbApp = await db.GetParameterAsync<AppName>();

Save logs to DB

ILogEntry log = new LogEntry
{
    Message = "Test message",
    Parameters = app,
    Source = "Tests",
    Level = LogLevel.Error
};
await db.WriteLogAsync(log);

Get logs

var logs = await db.GetLogsAsync(level: LogLevel.Error)
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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
1.0.1 213 4/20/2022

Ready to use