0

我需要调试PM> add-migration <name>你是怎么做的?

背景:它会引发以下错误。我要找谁的原因

System.ArgumentNullException: Value cannot be null.
Parameter name: derivedType
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
   at Microsoft.EntityFrameworkCore.EntityTypeExtensions.IsAssignableFrom(IEntityType entityType, IEntityType derivedType)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c__DisplayClass55_1.<StopTracking>b__0(INavigation n)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StopTracking(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Nullable`1 forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDataOperations()+MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
   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)
Value cannot be null.
4

1 回答 1

0

连接字符串时最常见的错误是null.

这不是你要找的东西,但无论如何,它可以帮助你。尝试记录错误或调试信息:

    public class Startup
    {
        private ILogger<Startup> Logger { get; }    
        public Startup(ILogger<Startup> logger)
        {
            Logger = logger;
        }    

        public void ConfigureServices(IServiceCollection services)
        {
            Logger.LogError("test");  <========= It will output messages


            string connection = null;
            services.AddDbContext<TestContext>(builder => builder.UseSqlServer(connection));

            ...
        }
        ...
    }
于 2018-12-06T14:43:36.377 回答