© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
14 replies
hutonahill

✅ .NET 8 Identity with SQLite

I am trying to implement .NET identity using a SQLite database.

I've followed this tutorial which uses SQL Sever. Ive gotten up to 14:48 (run the app) where i tested the API using Swagger. I created an email and password that passed all the default requirements, but got a SQLite exception that a table didn't exist.

assume at some point in this tutorial i did something that was supposed to set up the tables for SQL Server, but it does not work for SQLite.

Here's what i did.

I created a DataContext that extends IdentityDbContext with a constructer that passes a DbContextOptions<DataContext> to the base constructer

i added these lines to my progam.cs
builder.Services.AddDbContext<DataContext>(options =>
            options.UseSqlite(builder.Configuration.GetConnectionString("AuthConnection")));

        builder.Services.AddAuthorization();

        builder.Services.AddIdentityApiEndpoints<IdentityUser>()
            .AddEntityFrameworkStores<DataContext>();
...
app.MapIdentityApi<IdentityUser>();
builder.Services.AddDbContext<DataContext>(options =>
            options.UseSqlite(builder.Configuration.GetConnectionString("AuthConnection")));

        builder.Services.AddAuthorization();

        builder.Services.AddIdentityApiEndpoints<IdentityUser>()
            .AddEntityFrameworkStores<DataContext>();
...
app.MapIdentityApi<IdentityUser>();


i added my connection string to appsettings.json:
"ConnectionStrings": {
    "AuthConnection": "Data Source=auth.db;"
  },
...
"ConnectionStrings": {
    "AuthConnection": "Data Source=auth.db;"
  },
...


i ran this on PowerShell in my project directory
dotnet ef migrations add Initial
dotnet ef migrations add Initial


I've got the following packages installed (related to my attempt to implement identity):
- Microsoft.AspNetCore.Identiy.EntityFrameworCore
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Sqlite
- Microsoft.EntityFrameworkCore.Tools

This is my first foray into Data Contexts and Entity Framework. I am still not quite sure what ether are.
YouTubePatrick God
.NET 8 Authentication with Identity in a Web API with Bearer Tokens...
🚀 Join the .NET Web Academy: https://learn.dotnetwebacademy.com

💖 Support me on Patreon for exclusive source code access: https://patreon.com/_PatrickGod
🚀 Get the .NET 8 Web Dev Jump-Start Course for FREE: https://dotnet8.patrickgod.com
🐦 Let's get social on Twitter/X: https://twitter.com/_PatrickGod
🔗 Let's connect on LinkedIn: https://www.li...
.NET 8 Authentication with Identity in a Web API with Bearer Tokens...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Identity .NET 8
C#CC# / help
2y ago
.NET 8 SPA Identity
C#CC# / help
2y ago
✅ Configuring .NET 8 Identity
C#CC# / help
2y ago
.Net 8 Blazor Web App Identity Framework Help
C#CC# / help
3y ago