【发布时间】:2021-03-07 15:31:45
【问题描述】:
我使用 XAF Blazor 20.2.3 向导创建了一个新项目
并将 EFCore 包升级到 5.0。
在下午我跑了
Install-Package Microsoft.EntityFrameworkCore.Tools
但是当我跑步时
add-migration initial
我明白了
无法创建“ExamBuddyEFCoreDbContext”类型的对象。有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
我查看了该链接,但我认为它不适用于 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
结果是
启动项目“ExamBuddy.Module”以框架“.NETStandard”为目标。该框架没有关联的运行时,不能直接执行针对它的项目。要在此项目中使用 Entity Framework Core 包管理器控制台工具,请添加一个针对 .NET Framework 或引用此项目的 .NET Core 的可执行项目,并将其设置为启动项目;或者,将此项目更新为跨目标 .NET Framework 或 .NET Core。有关在 .NET Standard 项目中使用 EF Core 工具的更多信息,请参阅https://go.microsoft.com/fwlink/?linkid=2034705
[更新]
我在 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
【问题讨论】:
标签: entity-framework-core entity-framework-migrations blazor-server-side xaf