I finished coding my .NET MAUI application and everything was working fine in debug mode. All my data persistence needs were being met by Entity Framework Core for Xamarin, even though I am using it on .NET MAUI.
I have made the apk file and was testing it to see if everything was okay, but turns out the database is not being created. My application crashes once I attempt to do database operations. So I am not sure if it is incompatibility of EF Core with .NET MAUI (but it was working fine in debug) or there is something I missed.
I followed the tutorial accessed here https://learn.microsoft.com/en-us/ef/core/get-started/xamarin And below is my DataContext file
DataContext.cs
using Microsoft.EntityFrameworkCore;
using MedbaseRec.Models;
namespace MedbaseRec.Utils
{
public class DataContext : DbContext
{
public DbSet<QuestionPack> QuestionPacks { get; set; }
public DbSet<Question> Questions { get; set; }
public DataContext()
{
SQLitePCL.Batteries_V2.Init();
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "medbaseapplica.db3");
optionsBuilder.UseSqlite($"Filename={dbPath}");
}
}
}