Value cannot be null. Name of parameter: entitySet

Asked

Viewed 251 times

0

I am trying to make a project of an e-commerce of Petshop in ASP.NET MVC with Entityframework. Everything was going well, until suddenly, when I tried to register or even list Vendor, this error appeared:

[ArgumentNullException: Valor não pode ser nulo. Nome do parâmetro: entitySet]

One day it was working super well, and the next day it just wasn’t. I tried to fix it by going through Connectionstring, Identitymodels and Dbmodels:

Web.config (Connectionstring):

  <connectionStrings>
   <add name="Conexao" connectionString="server=localhost;user id=root;password=12345678;persistsecurityinfo=True;database=dbpetshop" providerName="MySql.Data.MySqlClient" />
   <add name="DBModel" connectionString="server=localhost;user id=root;password=12345678;persistsecurityinfo=True;database=dbpetshop" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>

Identitymodels:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DBModel", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

Dbmodels:

public partial class DBModels : DbContext
{
    public DBModels()
        : base("name=DBModel")
    {
    }

    public virtual DbSet<cliente> cliente { get; set; }
    public virtual DbSet<endereco> endereco { get; set; }
    public virtual DbSet<fornecedor> fornecedor { get; set; }
    public virtual DbSet<itemvenda> itemvenda { get; set; }
    public virtual DbSet<login> login { get; set; }
    public virtual DbSet<produto> produto { get; set; }
    public virtual DbSet<venda> venda { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<cliente>()
            .Property(e => e.NomeCli)
            .IsUnicode(false);

        modelBuilder.Entity<cliente>()
            .Property(e => e.CPF)
            .IsUnicode(false);

        modelBuilder.Entity<cliente>()
            .Property(e => e.RG)
            .IsUnicode(false);

        modelBuilder.Entity<cliente>()
            .Property(e => e.RG_dig)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.CEP)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.Logradouro)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.NomeBairro)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.NomeCidade)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.UF)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .Property(e => e.CompEnd)
            .IsUnicode(false);

        modelBuilder.Entity<endereco>()
            .HasMany(e => e.cliente)
            .WithRequired(e => e.endereco)
            .HasForeignKey(e => e.IdEndCli)
            .WillCascadeOnDelete(false);

        modelBuilder.Entity<endereco>()
            .HasMany(e => e.fornecedor)
            .WithOptional(e => e.endereco)
            .HasForeignKey(e => e.IdEndFornec);

        modelBuilder.Entity<fornecedor>()
            .Property(e => e.CNPJ)
            .IsUnicode(false);

        modelBuilder.Entity<fornecedor>()
            .Property(e => e.NomeFornec)
            .IsUnicode(false);

        modelBuilder.Entity<login>()
            .Property(e => e.Usuario)
            .IsUnicode(false);

        modelBuilder.Entity<login>()
            .Property(e => e.Senha)
            .IsUnicode(false);

        modelBuilder.Entity<produto>()
            .Property(e => e.NomeProd)
            .IsUnicode(false);

        modelBuilder.Entity<produto>()
            .Property(e => e.DescProd)
            .IsUnicode(false);

        modelBuilder.Entity<venda>()
            .Property(e => e.CPF)
            .IsUnicode(false);
    }
}

But nothing worked, I tried to find also people who went through the same problem, but none of them fit with my problem. What could have happened to appear this error?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.