ARTICLE AD BOX
’m building a basic SQL database application in C# using ASP.NET Core, Entity Framework Core, SQLite, and Identity. Below are my notes and steps exactly as I’ve written them. I want to know if this setup is correct and suitable for a basic database project, or if I’ve made any mistakes.
Dotnet new tool-manifest
Dotnet tool install dotnet-ef --version 8
Dotnet tool install dotnet-aspnet-codegenerator --version 8
Dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 8.0.0
Dotnet add package Microsoft.EntityFrameworkCore.Tools --version 8.0.0
Dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore --version 8.0.0
Dotnet add package Microsoft.AspNetCore.Identity.UI --version 8.0.0
Dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 8.0.0
Dotnet restore --force
Class to models
Guid string decimal
Data folder in solution
Add class app db context
Using framework core and name.models
Appdbcontext:dbcontext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Product> Products => Set<Product>();
appsettings
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=app.db"
Program cs
Add data strings
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
builder.Configuration.GetConnectionString("DefaultConnection")));
migrations add initialcreate
database update
new scaffolded item in controllers
click mvc on left then with views
model class = product
db context = appdbcontext
app db context
using Microsoft.AspNetCore.Identity.EntityFrameworkCore at top
dbcontext -> identitydbcontext
program.cs
builder.Services
.AddDefaultIdentity<IdentityUser>(options =>
{
options.SignIn.RequireConfirmedAccount = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>();
Above use authorisation
app.UseAuthentication();
add app.MapRazorPages(); above app.Run();
dotnet ef Migrations add AddIdentity
dotnet ef database update
in main section at top add new scaffolded item
click identity then add
override all files
