2017-09-23 12 views
0

最初にefコードでマイグレーションを追加するとエラーが発生しますが、コード内にエラーの位置が見つかりません。 abpフレームワーク。 パッケージマネージャコンソールでコマンドを実行すると、エラーの場所を見つける方法。 しかし、DbContextからすべてのカスタムエンティティを削除してマッピングファイルを削除すると、このエラーは表示されません。Nullableオブジェクトに値が必要です。add migration abp v 3.0.0

スタックトレース:

PM> add-migration Init_Db 
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] 
     User profile is available. Using 'C:\Users\Adam\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. 
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Nullable object must have a value. 
System.InvalidOperationException: Nullable object must have a value. 
    at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) 
    at System.Nullable`1.get_Value() 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.DetachRelationship(ForeignKey foreignKey) 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasBaseType(EntityType baseEntityType, ConfigurationSource configurationSource) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.DerivedTypeDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode node) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAddedNode.Accept(ConventionVisitor visitor) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionScope.Accept(ConventionVisitor visitor) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run() 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose() 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.DiscoverRelationships(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder) 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.AddEntityType(EntityType entityType) 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.AddEntityType(Type type, ConfigurationSource configurationSource) 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(TypeIdentity type, ConfigurationSource configurationSource) 
    at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource) 
    at Microsoft.EntityFrameworkCore.ModelBuilder.Entity(Type type) 
    at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.FindSets(ModelBuilder modelBuilder, DbContext context) 
    at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.FindSets(ModelBuilder modelBuilder, DbContext context) 
    at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context) 
    at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context) 
    at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) 
    at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.<GetModel>b__0(Object k) 
    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) 
    at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) 
    at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() 
    at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() 
    at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_1(IServiceProvider p) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) 
    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) 
    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) 
    at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() 
    at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider() 
    at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance() 
    at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor) 
    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory) 
    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) 
    at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0() 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) 
Nullable object must have a value. 
+0

カスタムエンティティのいずれかに自己参照関係がありますか?それ以外の場合は、カスタムエンティティを1つずつ削除して原因を絞り込んで表示できますか? – aaron

+0

エンティティのマッピングを書いたとき、私はあなたのソリューションとのマッピングエラーを解決しましたが、それは非常に困難で時間がかかります。しかし、あなたは私に良いヒント "自己参照関係"を与えました。 – rahim

+0

私はまだチェックしていません。 – rahim

答えて

0

は2日後、私はエラーの原因がコメントしたコード

public abstract class EntityMapConfiguration<T> : DbEntityConfiguration<T> where T : class 
{ 
    public override void Configure(EntityTypeBuilder<T> entity) 
    { 
     //if (typeof(ICreationAudited<ApplicationUser>).GetTypeInfo().IsAssignableFrom(typeof(T))) 
     //{ 
     // entity.HasOne(nameof(ICreationAudited<ApplicationUser>.CreatorUser)) 
     //  .WithOne() 
     //  .HasForeignKey(typeof(T), "CreatorUserId"); 
     //} 
     //if (typeof(IModificationAudited<ApplicationUser>).GetTypeInfo().IsAssignableFrom(typeof(T))) 
     //{ 
     // entity.HasOne(nameof(IModificationAudited<ApplicationUser>.LastModifierUser)) 
     //  .WithOne() 
     //  .HasForeignKey(typeof(T), "LastModifierUserId"); 
     //} 

     if (typeof(IHasConcurrency).GetTypeInfo().IsAssignableFrom(typeof(T))) 
      entity.Property(nameof(IHasConcurrency.RowVersion)).IsRowVersion(); 
    } 
} 

あり、最終的にコードを次のようにマッピングエラーを解決するため、エラー

を見つけましたが、私Efコア1とEfコア2でマッピングが問題なく動作した理由を理解できない

entity.HasOne(x => x.Bank).WithOne().HasForeignKey<BankAccount>(x => x.BankId); 
関連する問題