PM> Add-Migration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following parameters:
Name: Initial
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
at EFarmerPkModelLibrary.Context.EFarmerDbModel.OnConfiguring(DbContextOptionsBuilder optionsBuilder) in D:\New folder\projects\Agri-Project\ServerApp\EFarmer.pk\EntityModelLibrary\Entities\EFarmerModel.EFarmerDbModel.cs:line 57
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.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.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: connectionString
Я получаю эту ошибку при создании миграции
Ниже приведена моя конфигурация класса DbContext
string connectionString;
public EFarmerDbModel() :
base()
{
OnCreated();
}
public EFarmerDbModel(DbContextOptions options) :
base(options)
{
OnCreated();
}
public EFarmerDbModel(string connectionString) :
base(GetOptions(connectionString))
{
this.connectionString = connectionString;
OnCreated();
}
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
//{
// optionsBuilder.UseLazyLoadingProxies()
// .UseSqlServer(connectionString);
// base.OnConfiguring(optionsBuilder);
//}
private static DbContextOptions GetOptions(string connectionString)
{
return SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder(), connectionString).Options;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLazyLoadingProxies()
.UseSqlServer(connectionString);
optionsBuilder.UseSqlServer(connectionString,
x => x.MigrationsAssembly("EFarmerPkModelLibrary.Migrations"));
CustomizeConfiguration(ref optionsBuilder);
base.OnConfiguring(optionsBuilder);
}
partial void CustomizeConfiguration(ref DbContextOptionsBuilder optionsBuilder);
Я хочу упомянуть здесь, что у меня есть скаффолд Db Context и сущности рамочный класс путем обратного инжиниринга базы данных. И я использую Entity Framework в файле библиотеки.