Sample built with .Net MAUI.
This sample implements SQLite with Entity Framework Core.
the application is based on three projects:
- A Domain project for the models
- An Infrastructure project for database management
- The MAUI project
Before the first launch, be sure to perform a migration in the Infrastructure project
dotnet ef migrations add Initial_Create
dotnet ef database update
If you add a new migrations, make previous commands
Don't use Database.EnsureCreated() for SQLite otherwise the migrations will no longer work
To change the path of the .db file, you must edit the BlogContextFactory file and in the BlogContext (An appsettings.json file is recommended)
public class BlogContextFactory : IDesignTimeDbContextFactory<BlogContext>
{
public BlogContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<BlogContext>();
var sqlitePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "blog.db");
optionsBuilder.UseSqlite($"Data Source={sqlitePath}");
return new BlogContext(optionsBuilder.Options);
}
}There are many .NET related projects on GitHub.
- .NET home repo - links to hundreds of .NET projects, from Microsoft and the community.
- ASP.NET Core home - the best place to start learning about ASP.NET Core.
.NET (including the maui-samples repo) is licensed under the MIT license.