Important
This repository is archived. linq2db.Identity was overhauled and moved into the main linq2db repository: it
now uses the standard ASP.NET Core Identity entity types and EF Core's AspNet* schema, takes any linq2db
IDataContext, and follows linq2db's own release line. The new version ships with linq2db 6.6.0 under the same
NuGet package id, linq2db.Identity.
- Current source and documentation:
Source/LinqToDB.Identityin linq2db/linq2db - Moving from this version: the Migrating from the standalone
linq2db.Identitysection of that readme - The migration pull request: linq2db/linq2db#5640
- Issues and questions: linq2db/linq2db issues
The 6.0.0 API documented below is not compatible with the new version. The code here is kept for reference only.
LinqToDB Identity store provider for ASP.NET Core Identity
- Release builds can be found on NuGet
- MyGet
- V2
https://www.myget.org/F/linq2db/api/v2 - V3
https://www.myget.org/F/linq2db/api/v3/index.json
- V2
Install package:
PM> Install-Package linq2db.Identity
In general this is the same as for Entity Framework, just call AddLinqToDBStores instead of AddEntityFrameworkStores in your Startup.cs like here:
services.AddIdentity<ApplicationUser, IdentityRole>(options => {
options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.CookieName = "Interop";
options.Cookies.ApplicationCookie.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
})
.AddLinqToDBStores(new DefaultConnectionFactory()) //here
.AddDefaultTokenProviders();The main difference with Entity Framework Core storage provider are:
- We do not use hardcoded classes - interfaces like
IIdentityUser<TKey>are used (but yes, we do have default implementation) - Data connection factory is used for calling to database
We do not use any default mapping attributes on default POCOs (IdentityUser, IdentityRole and so on). This is because this types can be used on different environvents.
If in some reason you prefere using default POCOs you can use fluent mapping in your Startup.cs to define needed attributes.
For example to treat Id as identity:
LinqToDB.Mapping.MappingSchema.Default.GetFluentMappingBuilder()
.Entity<IdentityUser<int>>()
.HasIdentity(_ => _.Id);All source code is based on original Microsoft Entity Framework Core storage provider for ASP.NET Core Identity.
Tests and sample are just adopted for using LinqToDB. For inmemory storage tests SQLite inmemory database is used.