Be sure your Maui project is a single target of windows only. Remove the any Android and iOS targets.
If the dbcontext is in a library (best practice) you could make a seperate hosting windows project to run the migrations in.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
I am working on an application for the Windows platform using Blazor Hybrid MAUI and want to create a SQLite database with multiple tables using EF Core for the migration. I have already defined the ApplicationDbContext.cs
file and added it to MauiProgram.cs
. However, when I try to migrate, I receive the following error message:
PM> add-migration Initial Build started... Build succeeded. Startup project 'MauiAppDT' targets platform 'Android'. The Entity Framework Core Package Manager Console Tools don't support this platform. See https://aka.ms/efcore-docs-pmc-tfms for more information.
Have you an idea how I can fix this error?
Thanks in advance
applicationDbContext.cs
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source = C:\\App\\maui\\BaseSQLite\\db.sqlite");
}
public DbSet<SuiviBE> SuiviBEs { get; set; }
public DbSet<ActionItem> ActionItems { get; set; }
public DbSet<ADT> ADTs { get; set; }
public DbSet<EcoRep> EcoReps { get; set; }
public DbSet<TodoListModel> TodoListModels { get; set; }
public DbSet<CMMAction> cMMActions { get; set; }
public DbSet<ProjetModel> ProjetModels { get; set; }
public DbSet<ActionItemProjet> ActionItemProjets { get; set; }
public DbSet<Developer> Developers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ActionItem>()
.HasOne(p => p.SuiviBE)
.WithMany(b => b.ActionItems);
modelBuilder.Entity<ActionItemProjet>()
.HasOne(p => p.ProjetModel)
.WithMany(b => b.ActionItemProjets);
}
}
In MauiPrograms.cs
...
builder.Services.AddDbContext<ApplicationDbContext>();
...
Be sure your Maui project is a single target of windows only. Remove the any Android and iOS targets.
If the dbcontext is in a library (best practice) you could make a seperate hosting windows project to run the migrations in.