I created a new project with the XAF Blazor 20.2.3 wizard
and upgraded the EFCore packages to 5.0.
In PM I ran
Install-Package Microsoft.EntityFrameworkCore.Tools
However when I run
add-migration initial
I get
Unable to create an object of type 'ExamBuddyEFCoreDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I have looked at the link but I don't think it applies to the xaf Blazor app.
I tried commenting out the Database Initializer
using System;
using DevExpress.ExpressApp.EFCore.Updating;
using Microsoft.EntityFrameworkCore;
using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy;
using DevExpress.Persistent.BaseImpl.EF;
using DevExpress.ExpressApp.Design;
using DevExpress.ExpressApp.EFCore.DesignTime;
using DevExpress.Persistent.Base;
namespace ExamBuddy.Module.BusinessObjects {
public class ExamBuddyContextInitializer : DbContextTypesInfoInitializerBase {
protected override DbContext CreateDbContext() {
var builder = new DbContextOptionsBuilder<ExamBuddyEFCoreDbContext>()
.UseSqlServer(@";");
return new ExamBuddyEFCoreDbContext(builder.Options);
}
}
//[TypesInfoInitializer(typeof(ExamBuddyContextInitializer))]
public class ExamBuddyEFCoreDbContext : DbContext {
public ExamBuddyEFCoreDbContext(DbContextOptions<ExamBuddyEFCoreDbContext> options) : base(options) {
}
public DbSet<ModuleInfo> ModulesInfo { get; set; }
public DbSet<ModelDifference> ModelDifferences { get; set; }
public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; }
public DbSet<PermissionPolicyRole> Roles { get; set; }
public DbSet<PermissionPolicyRoleBase> RolesBase { get; set; }
public DbSet<PermissionPolicyUser> Users { get; set; }
public DbSet<CourseUnit> CourseUnits { get; set; }
}
[Update]
I set the module project to be the start project then I ran
add-migration initial -verbose
the result was
Startup project 'ExamBuddy.Module' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core Package Manager Console Tools with this project, add an executable project targeting .NET Framework or .NET Core that references this project, and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core. For more information on using the EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034705
[Update]
Cross linking to the Dev Express ticket
I added the following to the ExamBuddy.Blazor.Server
public class ExamBuddyContextFactory : IDesignTimeDbContextFactory<ExamBuddyEFCoreDbContext>
{
public ExamBuddyEFCoreDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<ExamBuddyEFCoreDbContext>();
optionsBuilder.UseSqlServer(@"Integrated Security=SSPI;MultipleActiveResultSets=true;Pooling=false;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=ExamBuddy;ConnectRetryCount=0;");
return new ExamBuddyEFCoreDbContext(optionsBuilder.Options);
}
}
Experimenting in Package Manager Console and Adding ConsoleApp1 I have
PM> add-migration init
Build started...
Build succeeded.
Startup project 'ExamBuddy.Module' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core Package Manager Console Tools with this project, add an executable project targeting .NET Framework or .NET Core that references this project, and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core. For more information on using the EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034705
So I added ConsoleApp1 as a 3.1 .net core start up project and added references to the XAF projects
PM> add-migration init
Build started...
Build succeeded.
Unable to create an object of type 'ExamBuddyEFCoreDbContext'.
For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
The source is on GitHub