I am trying to use the package Abp.ZeroCore.EntityFramework
in a vanilla ASP.NET Boilerplate template project, targeting ASP.NET Core 2 with full .NET Framework.
The template includes Entity Framework Core, but I want to use Entity Framework 6 because it's much more reliable and has features Entity Framework Core is missing.
In order to get it to build, I created a classic .NET class library with the Abp.ZeroCore.EntityFramework
package, replicating the original .EntityFrameworkCore project included in the project template, but with code specific to EntityFramework 6, and configured all other projects to use this new module instead of the EF Core project.
Project builds successfully without any warnings, but when I try to create a migration I get a model validation error detailed below:
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.
So it looks like that some of the included models in Abp.ZeroCore package are not compatible with the Abp.ZeroCore.EntityFramework package.
Is this a know issue or there is a workaround for this error? Including a vanilla ASP.NET Boilerplate template using ASP.NET Core and Entity Framework 6 would be really useful.
I found the bug caused by faulty/duplicate CreateIndex entries:
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);
The fix will be included in the next minor version. You can upgrade to ABP v3.3 when it is released.