EFCore.DataForge
2.0.4
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
<PackageReference Include="EFCore.DataForge" Version="2.0.4" />
<PackageVersion Include="EFCore.DataForge" Version="2.0.4" />
<PackageReference Include="EFCore.DataForge" />
paket add EFCore.DataForge --version 2.0.4
#r "nuget: EFCore.DataForge, 2.0.4"
#:package EFCore.DataForge@2.0.4
#addin nuget:?package=EFCore.DataForge&version=2.0.4
#tool nuget:?package=EFCore.DataForge&version=2.0.4
EFCore.DataForge
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 | Versions 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.19)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- MongoDB.Driver (>= 3.4.3)
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.