ASP.NET Core -IdentityDbContext不会创建其他表,而仅创建身份表



我正在使用add-mogration initial来创建数据库,但它只创建身份表,而不会创建表格分类。有什么想法我在做什么错?

using Ecommerce.Core;
using Ecommerce.Core.Domain.Categorias;
using Ecommerce.Core.Domain.Roles;
using Ecommerce.Core.Domain.Usuarios;
using Ecommerce.Data.ModelExtensions;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Ecommerce.Data
{
    public class EcommerceContext : IdentityDbContext<Usuario, Role, int>
    {
        public EcommerceContext(DbContextOptions<EcommerceContext> options) : base(options) { }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            //builder.AddEntityConfigurationsFromAssembly(GetType().Assembly);
            builder.Entity<Categoria>(c =>
            {
                c.ToTable("Categoria");
                c.HasKey(i => i.Id);
                c.Property(i => i.Nome);
                c.Property(i => i.dataCadastro);
            });
        }
        public DbSet<Categoria> Categoria { get; set; }
    }
}
using Ecommerce.Core;
using Ecommerce.Core.Domain.Categorias;
using Ecommerce.Core.Domain.Roles;
using Ecommerce.Core.Domain.Usuarios;
using Ecommerce.Data.ModelExtensions;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Ecommerce.Data
{
    public class EcommerceContext : IdentityDbContext<Usuario, Role, int>
    {
        public DbSet<Categoria> Categoria { get; set; }
        public EcommerceContext(DbContextOptions<EcommerceContext> options) : base(options) { }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            //builder.AddEntityConfigurationsFromAssembly(GetType().Assembly);
            builder.Entity<Categoria>(c =>
            {
                c.ToTable("Categoria");
                c.HasKey(i => i.Id);
                c.Property(i => i.Nome);
                c.Property(i => i.dataCadastro);
            });
            base.OnModelCreating(builder);
        }
    }
}

您必须在实体配置之后致电base.OnModelCreating(builder);进行更改。

对不起,我的英语,希望它可以帮助您。

相关内容

  • 没有找到相关文章