无法创建 'MyEFCoreDbContext' 类型的对象 xaf Blazor EFCore
Unable to create an object of type 'MyEFCoreDbContext' xaf Blazor EFCore
我使用 XAF Blazor 20.2.3 向导创建了一个新项目
并将 EFCore 软件包升级到 5.0。
在下午我 运行
Install-Package Microsoft.EntityFrameworkCore.Tools
然而当我运行
add-migration initial
我明白了
Unable to create an object of type 'ExamBuddyEFCoreDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
我查看了 link,但我认为它不适用于 xaf Blazor 应用程序。
我尝试注释掉数据库初始化程序
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; }
}
[更新]
我将模块项目设置为启动项目,然后 运行
add-migration initial -verbose
结果是
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
[更新]
跨越 linking 到 the Dev Express ticket
我将以下内容添加到 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);
}
}
在包管理器控制台中进行试验并添加 ConsoleApp1 我有
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
所以我将 ConsoleApp1 添加为 3.1 .net 核心启动项目并添加了对 XAF 项目的引用
PM> add-migration init
Build started...
Build succeeded.
Unable to create an object of type 'ExamBuddyEFCoreDbContext'.
有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
来源是on GitHub
我按照 DevExpress 票证中的建议创建了 ExamBuddyContextFactory class
在 Module 项目中,然后能够创建初始迁移。
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);
}
}
我使用 XAF Blazor 20.2.3 向导创建了一个新项目
并将 EFCore 软件包升级到 5.0。
在下午我 运行
Install-Package Microsoft.EntityFrameworkCore.Tools
然而当我运行
add-migration initial
我明白了
Unable to create an object of type 'ExamBuddyEFCoreDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
我查看了 link,但我认为它不适用于 xaf Blazor 应用程序。
我尝试注释掉数据库初始化程序
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; }
}
[更新]
我将模块项目设置为启动项目,然后 运行
add-migration initial -verbose
结果是
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
[更新]
跨越 linking 到 the Dev Express ticket
我将以下内容添加到 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);
}
}
在包管理器控制台中进行试验并添加 ConsoleApp1 我有
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
所以我将 ConsoleApp1 添加为 3.1 .net 核心启动项目并添加了对 XAF 项目的引用
PM> add-migration init
Build started...
Build succeeded.
Unable to create an object of type 'ExamBuddyEFCoreDbContext'.
有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
来源是on GitHub
我按照 DevExpress 票证中的建议创建了 ExamBuddyContextFactory class 在 Module 项目中,然后能够创建初始迁移。
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);
}
}