Net4x.IdentityData
2.2.0.26250
dotnet add package Net4x.IdentityData --version 2.2.0.26250
NuGet\Install-Package Net4x.IdentityData -Version 2.2.0.26250
<PackageReference Include="Net4x.IdentityData" Version="2.2.0.26250" />
<PackageVersion Include="Net4x.IdentityData" Version="2.2.0.26250" />
<PackageReference Include="Net4x.IdentityData" />
paket add Net4x.IdentityData --version 2.2.0.26250
#r "nuget: Net4x.IdentityData, 2.2.0.26250"
#:package Net4x.IdentityData@2.2.0.26250
#addin nuget:?package=Net4x.IdentityData&version=2.2.0.26250
#tool nuget:?package=Net4x.IdentityData&version=2.2.0.26250
Net4x.IdentityData
ASP.NET Core Identity data contexts with renamed tables, an application-settings table, and a start-up schema updater that applies dated SQL scripts to an existing database.
Target frameworks: net6.0, net8.0, net10.0.
dotnet add package Net4x.IdentityData
What is in the package
| Type | Purpose |
|---|---|
ApplicationBaseDbContext |
IdentityDbContext with the Identity tables renamed, migrated once per context type on construction |
ApplicationDbContext |
Ready-to-use Identity context |
AppSettingsDbContext |
Standalone AppSettings key/value table |
ApplicationWithAppSettingsDbContext |
Identity tables and AppSettings in one context |
DatabaseUpdater |
Applies dated .sql update scripts to an existing database |
DbContextConnectionInitializer |
Builds connection strings from configuration keys |
SysAdminUtility |
Swaps in elevated credentials for the duration of a schema update |
Identity table names
ApplicationBaseDbContext maps the Identity model onto shorter table names:
| ASP.NET Core default | This package |
|---|---|
AspNetUsers |
User |
AspNetRoles |
Role |
AspNetUserRoles |
UserRoles |
AspNetUserClaims |
UserClaims |
AspNetUserLogins |
UserLogins |
AspNetRoleClaims |
RoleClaims |
AspNetUserTokens |
UserTokens |
Getting started
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("ConnectionStringApp")));
builder.Services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
The context migrates itself the first time one is constructed. Each concrete context type is
migrated once per process; ApplicationBaseDbContext._migrated = true suppresses migration
entirely when the schema is deployed out of band.
Application settings table
public class SettingsService(AppSettingsDbContext context)
{
public string? Get(string key) =>
context.AppSettings.SingleOrDefault(setting => setting.Key == key)?.Value;
}
Key is a varchar(500) primary key, Value a varchar(4000) defaulting to the empty string.
Applying SQL update scripts
EF migrations cover the schema the package owns. DatabaseUpdater covers everything else: hand
written scripts applied in order to a database that already exists.
using DapperLibrary.SqlServer.DbContexts;
// Register a Dapper provider once, at start-up.
SqlDapperContext.Use();
DatabaseUpdater.CreateInstance()
.UpdateDataBase<ApplicationDbContext>("ConnectionStringApp", @"C:\app\sql");
Name each script <anything><Database>_<yyyyMMdd>.sql, for example Widgets_20240729.sql:
- Scripts are selected by the eight digit stamp in the file name — digits in the directory path are ignored — and applied oldest first.
- Only scripts newer than the version already recorded are applied.
- Batches are split on a line containing only
GO(any line ending, optional repeat count). USEbatches are dropped; the connection decides the catalog.- The highest version applied without error is written to an
UpdateHistorytable, which the updater creates if it is missing. A script that fails is logged and leaves the remaining scripts pending for the next run.
UpdateDataBase is a start-up path and is deliberately quiet: if the database does not exist
yet, is unreachable, or no Dapper provider has been registered, it logs and returns rather than
taking the host down. Scripts are only applied when the resolved connection string uses SQL
authentication and sysadmin credentials are configured — see below.
Set ConfigurationVariables.Instance.DontUpdateDatabase = true to skip script application
altogether, and ConfigurationVariables.Instance.ProviderName (default
Microsoft.Data.SqlClient) to choose the provider used for the existence probe.
Configuration keys
Connection details are read through ConfigurationLibrary's ArgumentGetter, which draws on
app settings, environment variables and the command line. Every key may be suffixed with the
database name to override it for a single database — DatabaseUserIdWidgets beats
DatabaseUserId.
| Key | Meaning |
|---|---|
ConnectionString<Database> |
Connection string, or template, for one database |
ConnectionStringDefault |
Fallback used when there is no per-database entry |
DataSource |
Server, placeholder {2} |
DatabaseUserId |
User, placeholder {0} |
DatabasePassword |
Password, placeholder {1} |
ProviderName |
ADO.NET invariant provider name, default System.Data.SqlClient |
UseIntegratedSecurity |
Selects the integrated-security template when no connection string is configured |
SysAdminUserId |
Elevated user used while update scripts run |
SysAdminPassword |
Elevated password used while update scripts run |
A connection string may be a template with four positional placeholders — {0} user, {1}
password, {2} data source, {3} database. With nothing configured at all the built-in
template is used:
Initial Catalog={3};Data Source={2};User Id={0};Password={1};TrustServerCertificate=True;
SysAdminUtility puts SysAdminUserId / SysAdminPassword in place of the ordinary
credentials for as long as it is held, and restores them on Dispose. Both must be set for
SysAdminPatched to be true, which is what gates script application.
Developer-local overrides
A Local.txt — or Local.<username>.txt, which wins — next to the assembly is copied to
Local.config and layered over the packaged configuration the first time a connection is
initialised. It is an ordinary .config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="DataSource" value="localhost" />
<add key="DatabaseUserId" value="sa" />
</appSettings>
</configuration>
The override is a convenience: an unreadable file is logged and skipped, never fatal.
Building connection strings yourself
var initializer = DbContextConnectionInitializer<ApplicationDbContext>.Instance
.CreateContextConnectionInitializer();
initializer.GettingConnectionString += (_, e) => e.Value = Decrypt(e.Value);
using var connection = initializer.Connection;
DbContextConnectionInitializer<TContext>.Instance resolves the database name from the context
type. The non-generic DbContextConnectionInitializer.Instance has overloads taking a
DbContext type, a database name, a connection string name and database name, or a ready-made
ConnectionStringSettings. Either way a context type is reduced to a database name by stripping
the DbContext / Context suffix, so ApplicationDbContext reads configuration for
Application.
GettingConnectionString, GettingProviderName and GettingDatabaseName let a host rewrite
each resolved value — decrypting a password, redirecting to a tenant catalog. Subscribing to
ConnectionInitializerCreating and setting Cancel vetoes creation, which makes
CreateContextConnectionInitializer return null.
ProviderFactory is null when the named provider is not registered with
DbProviderFactories; register yours at start-up if you need a live Connection.
Source
Part of the Net4x common library set — https://bitbucket.org/pieroviano/identityapplication.
| Product | Versions 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 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 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. |
-
net10.0
- Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (>= 10.0.11)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 10.0.11)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.11)
- Microsoft.EntityFrameworkCore.Tools (>= 10.0.11)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Interfaces.Configuration (>= 2.5.0.26236)
- Net4x.DapperLibrary.Base (>= 1.9.9.26248)
-
net6.0
- Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (>= 6.0.32)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 6.0.32)
- Microsoft.EntityFrameworkCore.SqlServer (>= 6.0.32)
- Microsoft.EntityFrameworkCore.Tools (>= 6.0.32)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Interfaces.Configuration (>= 2.5.0.26236)
- Net4x.DapperLibrary.Base (>= 1.9.9.26248)
-
net8.0
- Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (>= 8.0.7)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 8.0.7)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.7)
- Microsoft.EntityFrameworkCore.Tools (>= 8.0.7)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Interfaces.Configuration (>= 2.5.0.26236)
- Net4x.DapperLibrary.Base (>= 1.9.9.26248)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Net4x.IdentityData:
| Package | Downloads |
|---|---|
|
Starb.StarbookWebApi.Data
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.2.0.26250 | 93 | 9/7/2026 |
| 2.2.0 | 259 | 3/31/2025 |