Indiko.Blocks.DataAccess.EntityFramework
2.1.2
dotnet add package Indiko.Blocks.DataAccess.EntityFramework --version 2.1.2
NuGet\Install-Package Indiko.Blocks.DataAccess.EntityFramework -Version 2.1.2
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="Indiko.Blocks.DataAccess.EntityFramework" Version="2.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Indiko.Blocks.DataAccess.EntityFramework" Version="2.1.2" />
<PackageReference Include="Indiko.Blocks.DataAccess.EntityFramework" />
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 Indiko.Blocks.DataAccess.EntityFramework --version 2.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Indiko.Blocks.DataAccess.EntityFramework, 2.1.2"
#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 Indiko.Blocks.DataAccess.EntityFramework@2.1.2
#: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=Indiko.Blocks.DataAccess.EntityFramework&version=2.1.2
#tool nuget:?package=Indiko.Blocks.DataAccess.EntityFramework&version=2.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Indiko.Blocks.DataAccess.EntityFramework
Entity Framework Core implementation of the Indiko data access abstractions, providing full-featured ORM support for relational databases.
Overview
This package provides a complete Entity Framework Core implementation of the Indiko data access layer, supporting SQL Server, PostgreSQL, MySQL, SQLite, and other relational databases.
Features
- EF Core Integration: Full Entity Framework Core 9+ support
- Repository Implementation: Complete IRepository<TEntity, TIdType> implementation
- Unit of Work: Transaction management with EF Core
- DbContext: Base DbContext with automatic configuration
- Migrations Support: Full EF Core migrations support
- Change Tracking: Automatic entity state management
- Soft Delete: Built-in soft delete with query filters
- Design-Time Factory: Support for EF Core tools
- Model Builder: Fluent API configuration support
- Performance: No-tracking queries, compiled queries
- Multiple Databases: Support for SQL Server, PostgreSQL, MySQL, SQLite, Oracle
Installation
dotnet add package Indiko.Blocks.DataAccess.EntityFramework
Quick Start
Define Your DbContext
using Indiko.Blocks.DataAccess.EntityFramework;
public class AppDbContext : BaseDbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Apply entity configurations
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
}
}
Configure Services
public class Startup : WebStartup
{
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.UseEntityFrameworkDataAccess<AppDbContext>(options =>
{
options.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
options.DatabaseType = DatabaseType.SqlServer;
});
}
}
Entity Configuration
public class User : BaseEntity<Guid>
{
public string Name { get; set; }
public string Email { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("Users");
builder.HasKey(u => u.Id);
builder.Property(u => u.Name)
.IsRequired()
.HasMaxLength(200);
builder.Property(u => u.Email)
.IsRequired()
.HasMaxLength(256);
builder.HasIndex(u => u.Email).IsUnique();
builder.HasMany(u => u.Orders)
.WithOne(o => o.User)
.HasForeignKey(o => o.UserId);
}
}
Usage Examples
Basic CRUD
public class UserService
{
private readonly IRepository<User, Guid> _userRepository;
private readonly IUnitOfWork _unitOfWork;
public UserService(IRepository<User, Guid> userRepository, IUnitOfWork unitOfWork)
{
_userRepository = userRepository;
_unitOfWork = unitOfWork;
}
public async Task<User> CreateAsync(string name, string email)
{
var user = new User { Name = name, Email = email };
await _userRepository.AddAsync(user);
await _unitOfWork.SaveChangesAsync();
return user;
}
public async Task<User> GetByIdAsync(Guid id)
{
return await _userRepository.ReadByIdAsync(id);
}
public async Task<IEnumerable<User>> GetActiveUsersAsync()
{
return await _userRepository.ReadManyByQueryAsync(u => u.Status == Status.Active);
}
}
Eager Loading
// Load user with orders
var user = await _userRepository.ReadByIdAsync(
userId,
asNotracking: false,
includes: u => u.Orders
);
// Load user with nested navigation properties
var user = await _userRepository.ReadByIdAsync(
userId,
asNotracking: true,
includes: new Expression<Func<User, object>>[]
{
u => u.Orders,
u => u.Orders.Select(o => o.Items)
}
);
// Using string-based includes
var users = await _userRepository.ReadManyByQueryWithIncludesAsync(
where: u => u.IsActive,
asNotracking: true,
includes: "Orders", "Orders.Items", "Profile"
);
Queries with Projections
// Select specific properties
var userDtos = await _userRepository.ReadByQueryWithSelectorAsync(
where: u => u.IsActive,
selector: u => new UserDto
{
Id = u.Id,
Name = u.Name,
Email = u.Email,
OrderCount = u.Orders.Count
}
);
// Paged projection
var pagedUserNames = await _userRepository.ReadByQueryWithSelectorPagedAsync(
where: u => u.IsActive,
selector: u => u.Name,
page: 1,
pageSize: 50
);
Transactions
public async Task ProcessOrderAsync(Order order)
{
await _unitOfWork.BeginTransactionAsync();
try
{
var orderRepo = _manager.GetRepository<Order, Guid>();
var inventoryRepo = _manager.GetRepository<InventoryItem, Guid>();
// Add order
await orderRepo.AddAsync(order);
// Update inventory
foreach (var item in order.Items)
{
var inventoryItem = await inventoryRepo.ReadByIdAsync(item.ProductId);
inventoryItem.Quantity -= item.Quantity;
await inventoryRepo.UpdateAsync(inventoryItem);
}
await _unitOfWork.SaveChangesAsync();
await _unitOfWork.CommitTransactionAsync();
}
catch
{
await _unitOfWork.RollbackTransactionAsync();
throw;
}
}
Configuration Options
appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=MyApp;Trusted_Connection=True;"
},
"DataAccess": {
"DatabaseType": "SqlServer",
"EnableSensitiveDataLogging": false,
"CommandTimeout": 30,
"MaxRetryCount": 3,
"EnableDetailedErrors": false
}
}
Code Configuration
services.UseEntityFrameworkDataAccess<AppDbContext>(options =>
{
options.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
options.DatabaseType = DatabaseType.SqlServer;
options.EnableSensitiveDataLogging = env.IsDevelopment();
options.CommandTimeout = 60;
});
Migrations
Create Migration
dotnet ef migrations add InitialCreate --context AppDbContext
Apply Migration
dotnet ef database update --context AppDbContext
Generate SQL Script
dotnet ef migrations script --context AppDbContext --output migration.sql
Design-Time DbContext Factory
public class AppDbContextFactory : BaseDbContextDesignTimeFactory<AppDbContext>
{
protected override AppDbContext CreateDbContext(DbContextOptions<AppDbContext> options)
{
return new AppDbContext(options);
}
}
Soft Delete
Entities inheriting from BaseEntity support soft delete:
// Soft delete (sets Status = Deleted)
await _userRepository.DeleteAsync(userId, useSoftDelete: true);
// Hard delete (removes from database)
await _userRepository.DeleteAsync(userId, useSoftDelete: false);
// Query filters automatically exclude soft-deleted entities
var activeUsers = await _userRepository.ReadAllAsync(); // Excludes deleted
Performance Tips
No-Tracking Queries
// For read-only scenarios
var users = await _userRepository.ReadManyByQueryAsync(
where: u => u.IsActive,
asNotracking: true // Faster, no change tracking overhead
);
AsQueryable for Complex Queries
var query = _userRepository.AsQueryable()
.Where(u => u.IsActive)
.Include(u => u.Orders)
.ThenInclude(o => o.Items)
.OrderByDescending(u => u.CreatedAt)
.Take(10);
var users = await query.ToListAsync();
Batch Operations
// More efficient than individual operations
await _userRepository.AddRangeAsync(users);
await _unitOfWork.SaveChangesAsync();
Supported Databases
- SQL Server (2012+)
- PostgreSQL (10+)
- MySQL (5.7+)
- SQLite (3.7+)
- Oracle (11g+)
- MariaDB (10.2+)
Target Framework
- .NET 10
Dependencies
Indiko.Blocks.DataAccess.AbstractionsMicrosoft.EntityFrameworkCore(9.0+)Microsoft.EntityFrameworkCore.Relational
License
See LICENSE file in the repository root.
Related Packages
Indiko.Blocks.DataAccess.Abstractions- Core data access abstractionsIndiko.Blocks.DataAccess.MongoDb- MongoDB implementationIndiko.Blocks.DataAccess.Marten- Event sourcing with MartenMicrosoft.EntityFrameworkCore.SqlServer- SQL Server providerNpgsql.EntityFrameworkCore.PostgreSQL- PostgreSQL provider
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- Indiko.Blocks.DataAccess.Abstractions (>= 2.1.2)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.1)
- Microsoft.Data.SqlClient (>= 7.0.0-preview3.25342.7)
- Microsoft.EntityFrameworkCore (>= 10.0.1)
- Microsoft.EntityFrameworkCore.InMemory (>= 10.0.1)
- Microsoft.EntityFrameworkCore.Sqlite (>= 10.0.1)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.DependencyModel (>= 10.0.1)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.15.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.15.0)
- System.Runtime.Caching (>= 10.0.1)
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 |
|---|---|---|
| 2.1.2 | 276 | 12/18/2025 |
| 2.1.1 | 646 | 12/2/2025 |
| 2.1.0 | 620 | 12/2/2025 |
| 2.0.0 | 286 | 9/17/2025 |
| 1.7.23 | 345 | 9/8/2025 |
| 1.7.22 | 201 | 9/8/2025 |
| 1.7.21 | 214 | 8/14/2025 |
| 1.7.20 | 233 | 6/23/2025 |
| 1.7.19 | 200 | 6/3/2025 |
| 1.7.18 | 203 | 5/29/2025 |
| 1.7.17 | 191 | 5/26/2025 |
| 1.7.15 | 146 | 4/12/2025 |
| 1.7.14 | 179 | 4/11/2025 |
| 1.7.13 | 158 | 3/29/2025 |
| 1.7.12 | 165 | 3/28/2025 |
| 1.7.11 | 181 | 3/28/2025 |
| 1.7.10 | 181 | 3/28/2025 |
| 1.7.9 | 178 | 3/28/2025 |
| 1.7.8 | 178 | 3/28/2025 |
| 1.7.5 | 202 | 3/17/2025 |
Loading failed