【问题标题】:How to use the Abp.ZeroCore.EntityFramework with a ASP.NET Core solution如何将 Abp.ZeroCore.EntityFramework 与 ASP.NET Core 解决方案一起使用
【发布时间】:2017-12-04 22:08:46
【问题描述】:

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

为了构建它,我使用 Abp.ZeroCore.EntityFramework 包创建了一个经典的 .NET 类库,复制了项目模板中包含的原始 .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 Core 和 Entity Framework 6 的普通 ASP.NET Boilerplate 模板将非常有用。

【问题讨论】:

    标签: aspnetboilerplate


    【解决方案1】:

    我发现了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。

    【讨论】:

    • 谢谢!看起来这是个问题
    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 2018-07-24
    • 2017-12-09
    • 2011-01-21
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    相关资源
    最近更新 更多