EFCore.DataForge 2.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package EFCore.DataForge --version 2.0.4
                    
NuGet\Install-Package EFCore.DataForge -Version 2.0.4
                    
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="EFCore.DataForge" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EFCore.DataForge" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="EFCore.DataForge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EFCore.DataForge --version 2.0.4
                    
#r "nuget: EFCore.DataForge, 2.0.4"
                    
#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.
#:package EFCore.DataForge@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EFCore.DataForge&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=EFCore.DataForge&version=2.0.4
                    
Install as a Cake Tool

EFCore.DataForge

NuGet NuGet Downloads

EFCore.DataForge is a lightweight utility library for Entity Framework Core that provides ready-to-use helpers for common database operations — including CRUD, bulk operations, and soft deletes — so you can write less boilerplate code and focus on your business logic. It demonstrates a common pattern for entity modeling with metadata such as creation date, update date, and deprecation status.


🚀 Features

  • Create, Read, Update, Delete helpers for EF Core entities
  • Bulk operations for insert, update, and delete
  • Soft delete support with query filters
  • Clean, reusable API for DbContext operations
  • Works with EF Core 8 and later
  • Easy to extend
  • EntityBase: Abstract base class with common properties for all entities.
  • Automatic Guid ID generation.
  • Timestamps for creation and last update.
  • Deprecation flag to mark entities as obsolete.
  • Supports both SQL and MongoDB
  • Options to either use SQL, Mongo or both

📦 Installation

Install from NuGet.org:

dotnet add package EFCore.DataForge

Or add it to your .csproj file:

<PackageReference Include="EFCore.DataForge" Version="x.y.z" />

Usage

Configurations: appsettings.json

"EFCoreDataForge": {
    "MongoDb": {
      "ConnectionString": "mongodb://localhost:27017",
      "DatabaseName": "KwikNestaMongoStore"
    }
}

1. SQL: Entity Structure

Entity Base (Your database entities must inherit this class)
public abstract class EntityBase
{
    public Guid Id { get; set; } Guid.NewGuid();
    public bool IsDeprecated { get; set; }
    public DateTime CreatedOn => DateTime.UtcNow;
    public DateTime LastUpdatedOn { get; set; } = DateTime.UtcNow;
}
User
public class User : EntityBase
{
    public string Name { get; set; } = string.Empty;
}

2. MongoDB: Entity Structure

User
public class User
{
    [BsonId]
    [BsonRepresentation(BsonType.String)] // or BsonType.Binary if you prefer
    public Guid Id { get; set; } = Guid.NewGuid();
    public string Name { get; set; } = string.Empty;
}

Register the package in the Program.cs or Startup.cs

// SQL
builder.Services.ConfigureEFCoreDataForge<TDbContext>();

// MongoDB
builder.Services.ConfigureMongoEFCoreDataForge();

// There is a non-public constructor you can call
// if you already have an instance of IMongoDatabase registered
builder.Services.AddScoped<IEFCoreMongoCrudKit>(sp =>
{
    var db = sp.GetRequiredService<IMongoDatabase>();
    return (IEFCoreMongoCrudKit)Activator.CreateInstance(
        typeof(EFCoreMongoCrudKit),
        nonPublic: true, // allow internal/private ctor
        args: new object[] { db } // pass in options
    )!;
});

// SQL and MongoDB
// You need to register only this if you're going to use both SQL and MongoDB
builder.Services.ConfigureEFCoreDataForgeManager<TContext>(builder.Configuration);

// There is a non-public constructor you can call
// if you already have an instance of IMongoDatabase registered
builder.Services.AddScoped<IEFCoreDataForgeManager>(sp =>
{
    var context = sp.GetRequiredService<TContext>();
    var db = sp.GetRequiredService<IMongoDatabase>();
    return (IEFCoreDataForgeManager)Activator.CreateInstance(
        typeof(EFCoreDataForgeManager),
        nonPublic: true, // allow internal/private ctor
        args: new object[] { context, db } // pass in options
    )!;
});

Method Usage

1. SQL
public class TestService 
{
    private readonly IEFCoreCrudKit _crudKit;
    public TestService(IEFCoreCrudKit crudKit)
    {
        _crudKit = crudKit;
    }

    public async Task AddUser(User user)
    {
        await _crudKit.InsertAsync(user);
    }

    public async Task<User?> GetUser(Guid id)
    {
        var user = await _repository
            .FindByIdAsync<User>(id, trackChanges: true);

        return user;
    }
}
2. MongoDB
public class TestService
{
    private readonly IEFCoreMongoCrudKit _mongoCrudKit;

    public TestService(IEFCoreMongoCrudKit mongoCrudKit)
    {
        _mongoCrudKit = mongoCrudKit;
    }

    public async Task AddOneUser(MongoDataForgeTestUser user)
    {
        await _mongoCrudKit.InsertAsync(user);
    }

    public async Task<MongoDataForgeTestUser?> GetSingleUser(Guid id)
    {
        return await _mongoCrudKit.FindOneAsync<MongoDataForgeTestUser>(u => u.Id.Equals(id));
    }
}
SQL and MongoDB
public class TestService
{
    private readonly IEFCoreDataForgeManager _dataForgeManager;

    public TestService(IEFCoreDataForgeManager mongoCrudKit)
    {
        _dataForgeManager = mongoCrudKit;
    }

    public async Task AddOneMongoUser(MongoDataForgeTestUser user)
    {
        await _dataForgeManager.Mongo.InsertAsync(user);
    }

    public async Task<MongoDataForgeTestUser?> GetSingleMongoUser(Guid id)
    {
        return await _dataForgeManager.Mongo.FindOneAsync<MongoDataForgeTestUser>(u => u.Id.Equals(id));
    }

    public async Task AddOneSQLUser(DataForgeTestUser user)
    {
        await _dataForgeManager.SQL.InsertAsync(user);
    }

    public async Task<DataForgeTestUser?> GetSingleSQLUser(Guid id)
    {
        return await _dataForgeManager.SQL.FindByIdAsync<DataForgeTestUser>(id, false);
    }
}
There are methods for delete, replace, update, count, and bulk insert and deletion,

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EFCore.DataForge:

Package Downloads
KwikNesta.Contracts.Core

Kwik Nesta services shared contracts

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.4 222 8/24/2025
2.1.3 211 8/24/2025
2.0.4 117 8/24/2025