Muonroi.EntityFrameworkCore.Configuration
1.0.0-alpha.16
dotnet add package Muonroi.EntityFrameworkCore.Configuration --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.EntityFrameworkCore.Configuration -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.EntityFrameworkCore.Configuration" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.EntityFrameworkCore.Configuration" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.EntityFrameworkCore.Configuration" />
paket add Muonroi.EntityFrameworkCore.Configuration --version 1.0.0-alpha.16
#r "nuget: Muonroi.EntityFrameworkCore.Configuration, 1.0.0-alpha.16"
#:package Muonroi.EntityFrameworkCore.Configuration@1.0.0-alpha.16
#addin nuget:?package=Muonroi.EntityFrameworkCore.Configuration&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.EntityFrameworkCore.Configuration&version=1.0.0-alpha.16&prerelease
Muonroi.EntityFrameworkCore.Configuration
Composable EF Core entity configuration with a template method pattern for schema-divergent multi-tenancy.
In multi-tenant deployments each site shares 70–80% of the same schema but diverges on a handful of column names, lengths, and constraints. This package provides two mechanisms to express that divergence cleanly: a base class (MEntityConfigurationBase<TEntity>) that separates core schema from site-specific overrides via ordered template methods, and a [SiteColumn] attribute (applied by SiteColumnExtensions.ApplySiteColumnOverrides) for lightweight declarative per-site remapping. It depends only on Muonroi.Core.Abstractions and Microsoft.EntityFrameworkCore.Relational.
Installation
dotnet add package Muonroi.EntityFrameworkCore.Configuration --prerelease
Quick Start
Option A — virtual method overrides (MEntityConfigurationBase<TEntity>)
Derive one configuration class per entity in your core library and override site-specific hooks in each site project:
// Core library — shared schema for all sites
public class OrderConfiguration : MEntityConfigurationBase<Order>
{
protected override void ConfigureTable(EntityTypeBuilder<Order> builder)
=> builder.ToTable("ORDERS").HasKey(e => e.Id);
protected override void ConfigureCoreColumns(EntityTypeBuilder<Order> builder)
{
builder.Property(e => e.OrderNo).HasColumnName("ORDER_NO").HasMaxLength(50);
builder.Property(e => e.Status).HasColumnName("STATUS").IsRequired();
}
}
// Site "BRAVO" — override only what differs
public class BravoOrderConfiguration : OrderConfiguration
{
protected override void ConfigureSiteColumns(EntityTypeBuilder<Order> builder)
=> builder.Property(e => e.OrderNo).HasColumnName("BOOKING_NUMBER").HasMaxLength(25);
}
Register via EF Core's assembly scan inside DbContext.OnModelCreating:
modelBuilder.ApplyConfigurationsFromAssembly(typeof(BravoOrderConfiguration).Assembly);
Option B — [SiteColumn] attribute + ApplySiteColumnOverrides
Annotate a site-specific entity class and call the extension once during model building:
public class BravoOrder
{
public long Id { get; set; }
[SiteColumn(Name = "BOOKING_NUMBER", MaxLength = 25)]
public string? BookingNo { get; set; }
[SiteColumn(IsRequired = true, DefaultValue = "N")]
public string? Status { get; set; }
// No attribute → convention: CONTAINER_NO
public string? ContainerNo { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ApplySiteColumnOverrides<BravoOrder>("BRAVO");
}
Properties without [SiteColumn] are automatically mapped to UPPER_SNAKE_CASE by convention (e.g. ContainerNo → CONTAINER_NO).
Features
- Template method base class —
MEntityConfigurationBase<TEntity>calls five ordered hooks:ConfigureTable→ConfigureCoreColumns→ConfigureCoreIndexes→ConfigureSiteColumns→ConfigureSiteIndexes. Core methods are abstract; site methods are virtual no-ops, making them optional to override. - EF-native discovery — implements
IEntityTypeConfiguration<TEntity>, soApplyConfigurationsFromAssemblypicks up all configurations without manual registration. - Declarative site column overrides —
[SiteColumn]attribute supports column name, max length, required constraint, default value, column type, and ignore (exclude from mapping). - UPPER_SNAKE_CASE convention —
SiteColumnExtensions.ApplySiteColumnOverridesappliesUPPER_SNAKE_CASEto all unmapped properties automatically, keeping convention consistent with the Dapper/ISiteColumnMaplayer. - Shared naming convention —
ToUpperSnakeCasedelegates toColumnNamingConvention.ToUpperSnakeCasefromMuonroi.Core.Abstractions, the single source of truth for column naming across EF Core and Dapper.
Configuration
No DI registration is required. MEntityConfigurationBase<TEntity> is consumed by EF Core's model-building pipeline directly. ApplySiteColumnOverrides is called inside DbContext.OnModelCreating.
API Reference
| Type | Purpose |
|---|---|
MEntityConfigurationBase<TEntity> |
Abstract base implementing IEntityTypeConfiguration<TEntity>. Calls five template methods in a fixed order. |
SiteColumnAttribute |
Attribute ([AttributeUsage(Property)]) for declarative per-site column overrides: Name, MaxLength, IsRequired, DefaultValue, HasColumnType, Ignore. |
SiteColumnExtensions |
Static class. ApplySiteColumnOverrides<TEntity>(ModelBuilder, string siteId) reads [SiteColumn] attributes and applies overrides; falls back to UPPER_SNAKE_CASE convention for unannotated properties. |
Samples
- TestProject.Service — demonstrates
[SiteColumn]attribute onBravoOrderandApplySiteColumnOverrideswired in a minimalDbContext. - TestProject.Service.IntegrationTests — xUnit tests verifying
[SiteColumn]attribute inspection andApplySiteColumnOverridescolumn mapping via the EF Core in-memory provider.
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Core.Abstractions— providesColumnNamingConvention.ToUpperSnakeCase, the shared naming source used by this package.Muonroi.Data.EntityFrameworkCore— the higher-level EF Core package (MDbContext, audit timestamping, soft-delete). UseMEntityConfigurationBase<TEntity>inside aMDbContextsubclass for the full stack.
License
Apache-2.0. See LICENSE-APACHE at the repository root.
| 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.24)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.24)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muonroi.EntityFrameworkCore.Configuration:
| Package | Downloads |
|---|---|
|
Muonroi.Data.EntityFrameworkCore
Entity Framework Core infrastructure for Muonroi: MDbContext with audit, soft-delete, multi-tenant filters, and repository base. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 117 | 6/22/2026 |
| 1.0.0-alpha.15 | 164 | 5/31/2026 |
| 1.0.0-alpha.14 | 160 | 5/15/2026 |
| 1.0.0-alpha.13 | 142 | 5/2/2026 |
| 1.0.0-alpha.12 | 85 | 4/2/2026 |
| 1.0.0-alpha.11 | 139 | 4/2/2026 |
| 1.0.0-alpha.9 | 77 | 3/30/2026 |
| 1.0.0-alpha.8 | 170 | 3/28/2026 |
| 1.0.0-alpha.7 | 71 | 3/27/2026 |
| 1.0.0-alpha.5 | 69 | 3/27/2026 |
| 1.0.0-alpha.4 | 76 | 3/27/2026 |
| 1.0.0-alpha.3 | 62 | 3/27/2026 |
| 1.0.0-alpha.2 | 64 | 3/26/2026 |