Database Setup

Learn how to setup your database

Database Setup & Configuration | BlazorForKids

Introduction

BlazorForKids is designed with simplicity and practicality in mind. By default, it uses SQL Server together with Entity Framework Core to support fast and reliable development of internal tools and intranet applications for companies and small teams.

While SQL Server is the default option, developers can choose to use other EF Core-compatible databases such as SQLite, PostgreSQL, MySQL, and more, based on their specific project needs.

Using a Custom Database Provider

You can switch the database provider by updating the Program.cs file in your Web project and installing the correct NuGet package.

Example: Switching to SQLite

  1. Install the EF Core package for SQLite:
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
  2. Update Program.cs:
    
                    builder.AddBlazorForKids<ApplicationDbContext>(options =>
                    {
                        options.DbContextOptions = (provider, optionsBuilder) =>
                        {
                            optionsBuilder
                                .UseSqlite("Data Source=myData.db")
                                .AddBlazorForKidsInterceptor(provider);
                        };
                    });
                
  3. Important: Always add .AddBlazorForKidsInterceptor(provider) when configuring the database. This enables features that the framework needs in order to work correctly with your selected provider.

Database Comparison Table

Here is a basic comparison to help you decide which database to start with. You can always change it later as your application grows.

Database When to Use Recommended For NuGet Package
SQL Server (Default) Ideal for enterprise apps, intranet, or tools with large datasets and multi-user environments Production-ready apps for companies or teams Microsoft.EntityFrameworkCore.SqlServer
SQLite Great for prototyping, small apps, or learning purposes; runs on a local file Beginners and solo developers Microsoft.EntityFrameworkCore.Sqlite
PostgreSQL Open-source, scalable and reliable; good for Linux servers and open environments Mid to advanced users looking for open-source options Npgsql.EntityFrameworkCore.PostgreSQL
MySQL / MariaDB Popular for web apps, often used with PHP but works well in .NET too Users with existing MySQL experience Pomelo.EntityFrameworkCore.MySql

Notes for Beginners

  • The default database (SQL Server) is fully configured and ready to use.
  • If you're just exploring the framework or building a demo, SQLite is a great starting point.
  • Make sure to install the correct NuGet package for your chosen database.
  • Always append .AddBlazorForKidsInterceptor(provider) to the optionsBuilder setup.

Summary

BlazorForKids gives you flexibility in choosing your database. Whether you're building a robust enterprise app or a small tool for learning, you can use the database that fits your scenario best. Start with what's easy, and evolve your stack as your needs grow.

An unhandled error has occurred. Reload 🗙