Compile-time ASP.NET Core Identity stores for Dapper.
If you like ASP.NET Core Identity but do not want EF Core in the store layer, this repository gives you source-generated stores and SQL for SQL Server, PostgreSQL, MySQL, Oracle, and SQLite.
- β‘ Fast runtime path powered by Dapper
- π§ Source-generated stores and provider-specific SQL instead of hand-written plumbing
- π§© Works with
string,int,long, andGuidkeys - ποΈ Supports custom Identity properties and custom column names
- ποΈ Covers SQL Server, PostgreSQL, MySQL, Oracle, and SQLite
- ποΈ Lets you skip normalized columns when you do not need them
- π§ͺ Backed by provider-specific unit and integration tests
| Provider | NuGet package | Default schema | Extra startup step |
|---|---|---|---|
| SQL Server | AdaskoTheBeAsT.Identity.Dapper.SqlServer |
dbo |
none |
| PostgreSQL | AdaskoTheBeAsT.Identity.Dapper.PostgreSql |
public |
PostgreSqlDapperConfig.ConfigureTypeHandlers(); |
| MySQL | AdaskoTheBeAsT.Identity.Dapper.MySql |
n/a | MySqlDapperConfig.ConfigureTypeHandlers(); |
| Oracle | AdaskoTheBeAsT.Identity.Dapper.Oracle |
empty by default | OracleDapperConfig.ConfigureTypeHandlers(); |
| SQLite | AdaskoTheBeAsT.Identity.Dapper.Sqlite |
n/a | SQLitePCL.Batteries.Init(); and SqliteDapperConfig.ConfigureTypeHandlers(); |
The shared runtime package is AdaskoTheBeAsT.Identity.Dapper; most applications install a provider package and let that pull in the core runtime.
# SQL Server
dotnet add package AdaskoTheBeAsT.Identity.Dapper.SqlServer
# PostgreSQL
dotnet add package AdaskoTheBeAsT.Identity.Dapper.PostgreSql
# MySQL
dotnet add package AdaskoTheBeAsT.Identity.Dapper.MySql
# Oracle
dotnet add package AdaskoTheBeAsT.Identity.Dapper.Oracle
# SQLite
dotnet add package AdaskoTheBeAsT.Identity.Dapper.Sqliteusing System.ComponentModel.DataAnnotations.Schema;
using AdaskoTheBeAsT.Identity.Dapper.Attributes;
using Microsoft.AspNetCore.Identity;
namespace MyApp.Identity;
public sealed class ApplicationRole : IdentityRole<Guid>
{
}
public sealed class ApplicationRoleClaim : IdentityRoleClaim<Guid>
{
}
[InsertOwnId]
public sealed class ApplicationUser : IdentityUser<Guid>
{
[Column("IsActive")]
public bool IsActive { get; set; }
}
public sealed class ApplicationUserClaim : IdentityUserClaim<Guid>
{
}
public sealed class ApplicationUserLogin : IdentityUserLogin<Guid>
{
}
public sealed class ApplicationUserRole : IdentityUserRole<Guid>
{
}
public sealed class ApplicationUserToken : IdentityUserToken<Guid>
{
}[InsertOwnId] is optional and useful when you want to keep external identity IDs unchanged.
Provider packages already ship sensible defaults. Add overrides only when you need them:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<AdaskoTheBeAsTIdentityDapper_SkipNormalized>false</AdaskoTheBeAsTIdentityDapper_SkipNormalized>
<AdaskoTheBeAsTIdentityDapper_DbSchema>dbo</AdaskoTheBeAsTIdentityDapper_DbSchema>
</PropertyGroup>The example below uses SQL Server, but the pattern is the same for other providers.
using AdaskoTheBeAsT.Identity.Dapper.Abstractions;
using Microsoft.AspNetCore.Identity;
using Microsoft.Data.SqlClient;
builder.Services.AddSingleton<IIdentityDbConnectionProvider<SqlConnection>, IdentityDbConnectionProvider>();
builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddUserStore<ApplicationUserStore>()
.AddRoleStore<ApplicationRoleStore>()
.AddDefaultTokenProviders();
public sealed class IdentityDbConnectionProvider : IIdentityDbConnectionProvider<SqlConnection>
{
private readonly IConfiguration _configuration;
public IdentityDbConnectionProvider(IConfiguration configuration)
{
_configuration = configuration;
}
public SqlConnection Provide() => new(_configuration.GetConnectionString("DefaultConnection")!);
}ApplicationUserStore, ApplicationUserOnlyStore, and ApplicationRoleStore are generated during build.
dotnet buildIf EmitCompilerGeneratedFiles is enabled, generated files are written to the folder configured by CompilerGeneratedFilesOutputPath.
This library generates store code and SQL access logic, but it does not create your database schema for you.
Use the scripts in db/:
db/SqlServer/contains SSDT-style.sqlprojschema projectsdb/PostgreSQL/,db/MySql/,db/Oracle/, anddb/SQLite/contain SQL scripts- scripts are available for
string,int,bigint, andGuidkeys - each provider includes normalized and
WithoutNormalized...variants
| Property | Default | Applies to | What it changes |
|---|---|---|---|
EmitCompilerGeneratedFiles |
false |
all providers | writes generated code to disk |
CompilerGeneratedFilesOutputPath |
Generated |
all providers | changes the generated output folder |
AdaskoTheBeAsTIdentityDapper_SkipNormalized |
false |
all providers | skips normalized role and user columns |
AdaskoTheBeAsTIdentityDapper_DbSchema |
dbo / public / empty |
SQL Server, PostgreSQL, Oracle | changes the schema prefix used by generated SQL |
AdaskoTheBeAsTIdentityDapper_StoreBooleanAs |
char |
Oracle only | stores booleans as char, number, or string |
- PostgreSQL: call
PostgreSqlDapperConfig.ConfigureTypeHandlers(); - MySQL: call
MySqlDapperConfig.ConfigureTypeHandlers(); - Oracle: call
OracleDapperConfig.ConfigureTypeHandlers(); - SQLite: call
SQLitePCL.Batteries.Init();andSqliteDapperConfig.ConfigureTypeHandlers();
samples/Sample.SqlServer2β SQL Server sample that consumes the NuGet packagessamples/Sample.SqlServerβ SQL Server sample that references local projectssrc/AdaskoTheBeAsT.Identity.Dapper.WebApiβ runnable Web API examplesamples/OracleConsoleApp/PrepareOracleDb.txtβ Oracle prep notesdb/β provider schema scripts and SQL Server schema projects
- .NET SDK
10.0.201(pinned inglobal.json) - Docker Desktop / Docker Engine for integration tests
- PowerShell for
clean.ps1 - Visual Studio + SSDT if you need to edit SQL Server
.sqlprojdatabase projects
# restore everything
dotnet restore AdaskoTheBeAsT.Identity.Dapper.sln
# recommended filtered build loop
dotnet build WithoutSqlDb.slnf
# focused MySQL loop
dotnet build MySQL.slnf
# run the Web API sample
dotnet run --project src/AdaskoTheBeAsT.Identity.Dapper.WebApi/AdaskoTheBeAsT.Identity.Dapper.WebApi.csproj
# run a provider unit snapshot test project
dotnet test test/unit/AdaskoTheBeAsT.Identity.Dapper.PostgreSql.Test/AdaskoTheBeAsT.Identity.Dapper.PostgreSql.Test.csproj
# run a provider integration test project (Docker required)
dotnet test test/integ/AdaskoTheBeAsT.Identity.Dapper.Sqlite.IntegrationTest/AdaskoTheBeAsT.Identity.Dapper.Sqlite.IntegrationTest.csproj
# clean bin/obj folders
pwsh ./clean.ps1src/
AdaskoTheBeAsT.Identity.Dapper/ shared runtime abstractions and base store types
AdaskoTheBeAsT.Identity.Dapper.SqlServer/ SQL Server source generator package
AdaskoTheBeAsT.Identity.Dapper.PostgreSql/ PostgreSQL source generator package
AdaskoTheBeAsT.Identity.Dapper.MySql/ MySQL source generator package
AdaskoTheBeAsT.Identity.Dapper.Oracle/ Oracle source generator package
AdaskoTheBeAsT.Identity.Dapper.Sqlite/ SQLite source generator package
AdaskoTheBeAsT.Identity.Dapper.WebApi/ runnable example app
db/ schema scripts and SQL Server schema projects
samples/ consumer samples and provider-specific notes
test/ provider unit snapshot tests and integration tests
Pull requests are welcome. A good contributor loop is:
- build the relevant solution filter (
WithoutSqlDb.slnforMySQL.slnf) - run the provider test project you touched
- keep generated SQL and snapshots aligned with the implementation
This project is licensed under the MIT License.
- Issues: https://github.com/AdaskoTheBeAsT/AdaskoTheBeAsT.Identity.Dapper/issues
- NuGet: https://www.nuget.org/packages/AdaskoTheBeAsT.Identity.Dapper/
If this library saves you time, a GitHub star is always appreciated.