如何将 Abp.ZeroCore.EntityFramework 与 ASP.NET 核心解决方案一起使用

How to use the Abp.ZeroCore.EntityFramework with a ASP.NET Core solution

我正在尝试在香草 ASP.NET 样板模板项目中使用包 Abp.ZeroCore.EntityFramework,目标是具有完整 .NET Framework 的 ASP.NET Core 2。 该模板包含 Entity Framework 核心,但我想使用 Entity Framework 6,因为它更可靠并且具有 Entity Framework 缺少核心的功能。

为了构建它,我使用 Abp.ZeroCore.EntityFramework 包创建了一个 classic .NET class 库,复制了原始的 .EntityFrameworkCore 项目包含在项目模板中,但代码特定于 EntityFramework 6,并将所有其他项目配置为使用这个新模块而不是 EF Core 项目。

项目构建成功,没有任何警告,但是当我尝试创建迁移时,出现模型验证错误,详情如下:

PM> Add-Migration InitialMigration
System.InvalidOperationException: The index with name 'IX_UserId_State_CreationTime' on table 'dbo.AbpUserNotifications' has the same column order of '1' specified for columns 'TenantId' and 'UserId'. Make sure a different order value is used for the IndexAttribute on each column of a multi-column index.
   at System.Data.Entity.Infrastructure.ConsolidatedIndex.Add(String columnName, IndexAttribute index)
   at System.Data.Entity.Infrastructure.ConsolidatedIndex.BuildIndexes(String tableName, IEnumerable`1 columns)
   at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<FindTargetIndexes>b__278(EntitySet es)
   at System.Linq.Enumerable.<SelectManyIterator>d__22`3.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(ModelMetadata source, ModelMetadata target, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion)
   at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion)
   at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The index with name 'IX_UserId_State_CreationTime' on table 'dbo.AbpUserNotifications' has the same column order of '1' specified for columns 'TenantId' and 'UserId'. Make sure a different order value is used for the IndexAttribute on each column of a multi-column index.

所以看起来 Abp.ZeroCore 包中包含的一些模型与 Abp.ZeroCore.EntityFramework 包不兼容。

这是已知问题还是有解决此错误的方法? 包括使用 ASP.NET 核心和 Entity Framework 6 的香草 ASP.NET 样板模板将非常有用。

我发现了由 faulty/duplicate CreateIndex 个条目引起的错误:

modelBuilder.Entity<UserNotificationInfo>()
    .Property(e => e.UserId)
    .CreateIndex("IX_UserId_State_CreationTime", 1);
modelBuilder.Entity<UserNotificationInfo>()
    .Property(e => e.TenantId)
    .CreateIndex("IX_UserId_State_CreationTime", 1);

修复将包含在下一个次要版本中。 ABP v3.3 发布后可升级