Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Utilizing AddSqlite in a Blazor application

$
0
0

I am following this guide on how to build a Blazor application. I am running into an issue with the line builder.Services.AddSqlite<PizzaStoreContext>("Data Source=pizza.db");.

The error I am getting is 'IServiceCollection' does not contain a definition for 'AddSqlite' and no accessible extension method 'AddSqlite' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

The program.cs file looks like this:

using BlazingPizza.Data;var builder = WebApplication.CreateBuilder(args);builder.Services.AddRazorPages();builder.Services.AddServerSideBlazor();builder.Services.AddSingleton<PizzaService>();builder.Services.AddHttpClient();builder.Services.AddSqlite<PizzaStoreContext>("Data Source=pizza.db");var app = builder.Build();if (!app.Environment.IsDevelopment()){    app.UseExceptionHandler("/Error");}app.UseStaticFiles();app.UseRouting();app.MapRazorPages();app.MapBlazorHub();app.MapFallbackToPage("/_Host");app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");// Initialize the databasevar scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();using (var scope = scopeFactory.CreateScope()){    var db = scope.ServiceProvider.GetRequiredService<PizzaStoreContext>();    if (db.Database.EnsureCreated())    {        SeedData.Initialize(db);    }}app.Run();

The PizzaStoreContext.cs looks like this:

using Microsoft.EntityFrameworkCore;namespace BlazingPizza.Data;public class PizzaStoreContext : DbContext{    public PizzaStoreContext(DbContextOptions options) : base(options)    {    }    public DbSet<PizzaSpecial> Specials { get; set; }}

This seems to match up with what is in the guide. What have I got wrong?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>