添加迁移或更新数据库导致Nuget软件包管理器挂起

时间:2019-03-16 09:54:53

标签: c# asp.net-core entity-framework-core asp.net-core-2.1

我正在为项目使用EF Core 2.3EF Sql Server。 当我尝试添加初始迁移时,显示了我的 Package Manager控制台

Microsoft.EntityFrameworkCore.Infrastructure [10403]       实体框架核心2.2.3-service-35854使用提供程序'Microsoft.EntityFrameworkCore.SqlServer'初始化了'CustomerSqlDbContext',选项为: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问题吗?

谢谢。

0 个答案:

没有答案