Я использую EF Core 2.3
и EF Sql Server
для своего проекта.
При попытке добавить начальную миграцию моя консоль диспетчера пакетов отображала:
Microsoft.EntityFrameworkCore.Infrastructure [10403]
Entity Framework Core 2.2.3-servicing-35854 инициализировал «CustomerSqlDbContext», используя поставщика «Microsoft.EntityFrameworkCore.SqlServer» с параметрами: MigrationsAssembly = Customer.Infrastructure
Он долго зависал, поэтому пришлось закрыть Visual Studio 2017 и снова открыть.
Вот мой CustomerSqlDbContext.cs
:
public class CustomerSqlDbContext : DbContext
{
#region Propertes
private readonly IConfiguration _configuration;
#endregion
#region Constructor
/// <summary>
/// Initalize db context with connection string pass
/// </summary>
public CustomerSqlDbContext(DbContextOptions dbContextOptions, IConfiguration configuration) : base(
dbContextOptions)
{
_configuration = configuration;
}
#endregion
#region Data set
/// <summary>
/// Customer table
/// </summary>
public DbSet<Domain.Entities.Customer> Customers { get; set; }
#endregion
#region Methods
/// <summary>
/// <inheritdoc />
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new CustomerEntityConfiguration());
// This is for remove pluralization naming convention in database defined by Entity Framework.
foreach (var entity in modelBuilder.Model.GetEntityTypes())
entity.Relational().TableName = entity.DisplayName();
// Disable cascade delete.
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}
/// <summary>
/// <inheritdoc />
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_configuration.GetConnectionString("SqlConnectionString"),
b => b.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name));
}
#endregion
}
Мой CustomerEntityConfiguration.cs
:
public class CustomerEntityConfiguration : IEntityTypeConfiguration<Domain.Entities.Customer>
{
#region Methods
/// <summary>
/// <inheritdoc />
/// </summary>
/// <param name="builder"></param>
public void Configure(EntityTypeBuilder<Domain.Entities.Customer> builder)
{
builder.HasKey(c => c.Id);
//Address value object persisted as owned entity in EF Core 2.0
builder.OwnsOne(o => o.Balance)
.Property(x => x.Current)
.HasColumnName("TotalBalance");
builder.OwnsOne(o => o.Balance)
.Property(x => x.Available)
.HasColumnName("AvaialbleBalance");
}
#endregion
}
Money
класс объекта значения:
public class Money : ValueObject
{
#region Properties
/// <summary>
/// The current amount money
/// </summary>
public double Current { get; private set; }
/// <summary>
/// The available amount money
/// </summary>
public double Available { get; private set; }
#endregion
#region Constructor
public Money(double current, double available)
{
Current = current;
Available = available;
}
#endregion
protected override IEnumerable<object> GetAtomicValues()
{
yield return Current;
yield return Available;
}
}
Я пробовал много раз, даже удалял старые пакеты nuget и восстанавливал их.
Мой менеджер пакетов Nuget постоянно зависал.
Это вопрос EF?
Спасибо.