
In a hosted Blazor WASM solution, Entity Framework Core runs on the server project — never on the WASM client. The client communicates with the server via API controllers or minimal API endpoints.
// AppDbContext.cs
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options) { }
public DbSet<Product> Products => Set<Product>();
}
// Program.cs (Server)
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(
builder.Configuration.GetConnectionString("Default")));app.MapGet("/api/products", async (AppDbContext db) =>
await db.Products.ToListAsync());
app.MapPost("/api/products", async (AppDbContext db, Product product) =>
{
db.Products.Add(product);
await db.SaveChangesAsync();
return Results.Created($"/api/products/{product.Id}", product);
});Keep model classes in the Shared project — both the Server EF Core context and the Client's HttpClient service reference the same types.
Reference:
TaskLoco™ — The Sticky Note GOAT