简体   繁体   中英

Asp.net Core - IdentityDbContext is not creating other tables, only the identity tables

I'm using Add-Migration Initial to create the databases but it only creates the Identity tables and don't create the table Categoria. Any ideas what am i doing wrong ?

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);
        }
    }
}

You have to call base.OnModelCreating(builder); after your entity configurations to changes take effect.

Sorry for my english, I hope it could help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM