C#C
C#2y ago
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>();


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


i ran this on PowerShell in my project directory
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
🚀 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...
Was this page helpful?