Error: EntityTypeT has no key defined. Define the key for this EntityType

1

When I run my application, the following error is generated:

  

One or more validation errors were detected during model generation:   BolaoSCA.DataAccess.Context.InstallMap:: EntityType 'InvalidMap' has no key defined. Set the key for this EntityType.   Bet Status1: EntityType: EntitySet 'BetPosted1' is based on type 'BetPostedMap' that has no keys defined.

Class Aposta Status

public class ApostaEstado
{
    public int Id { get; set; }
    public string Nome { get; set; }
}

Class ApostaMap

public class ApostaEstadoMap: EntityTypeConfiguration<ApostaEstado>
{
    public ApostaEstadoMap()
    {
        this.ToTable("ApostaEstado");
        this.HasKey(x => x.Id);

        //propriedades
        this.Property(x => x.Id).HasColumnName("ApostaEstadoId");
        this.Property(x => x.Nome).HasColumnName("ApostaEstadoNome");
    }
}

Script of the BetPoker table

CREATE TABLE ApostaEstado
(
    ApostaEstadoId int not null auto_increment,
    ApostaEstadoNome varchar(30) not null,

    primary key(ApostaEstadoId)
)Engine = InnoDB;

DataContext

public class DataContext : DbContext
{
    public DataContext() : base("name=ConnString") { }

    public virtual DbSet<TimeFutebol> TimesFutebol { get; set; }
    public virtual DbSet<Usuario> Usuario { get; set; }
    public virtual DbSet<Campeonato> Campeonato { get; set; }
    public virtual DbSet<PerfilAcesso> PerfilAcesso { get; set; }
    public virtual DbSet<Bolao> Bolao { get; set; }
    public virtual DbSet<SystemConfig> SystemConfig { get; set; }
    public virtual DbSet<Rodada> Rodada { get; set; }
    public virtual DbSet<Partida> Partida { get; set; }
    public virtual DbSet<RodadaEstado> RodadaEstado { get; set; }
    public virtual DbSet<ApostaEstadoMap> ApostaEstado { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        modelBuilder.Configurations.Add(new UsuarioMap());
        modelBuilder.Configurations.Add(new TimeFutebolMap());
        modelBuilder.Configurations.Add(new CampeonatoMap());
        modelBuilder.Configurations.Add(new BolaoMap());
        modelBuilder.Configurations.Add(new PerfilAcessoMap());
        modelBuilder.Configurations.Add(new SystemConfigMap());
        modelBuilder.Configurations.Add(new RodadaMap());
        modelBuilder.Configurations.Add(new PartidaMap());
        modelBuilder.Configurations.Add(new RodadaEstadoMap());
        modelBuilder.Configurations.Add(new ApostaEstadoMap());

        base.OnModelCreating(modelBuilder);
    }
}

For the StatePosted entity, I did EXACTLY the same process as the other entities. As for example the entity RondaEstado, that does not return me any error. Follow entity structure RoundState:

Class RoundState

public class RodadaEstado
{
    public int Id { get; set; }
    public string Nome { get; set; }

    public virtual ICollection<Rodada> Rodadas { get; set; }

    public RodadaEstado()
    {
        Rodadas = new HashSet<Rodada>();
    }
}

Class RoundStatusMap

public class RodadaEstadoMap: EntityTypeConfiguration<RodadaEstado>
{
    public RodadaEstadoMap()
    {
        this.ToTable("RodadaEstado");
        this.HasKey(x => x.Id);

        //propriedades
        this.Property(x => x.Id).HasColumnName("RodadaEstadoId");
        this.Property(x => x.Nome).HasColumnName("RodadaEstadoNome");
    }
}

Table Script RoundState

CREATE TABLE RodadaEstado
(
    RodadaEstadoId int not null auto_increment,
    RodadaEstadoNome varchar(30) not null,

    primary key(RodadaEstadoId)
)Engine = InnoDB;

I really do not know what to do. I've reviewed the StakeBox, StakeBox, DataContext, and bank script countless times to see if I was doing / typing something wrong. However, I did not find any structure or code errors.

PS: I tried the Data Annotation alternative when associating the [Key] notation with the Id attribute. I also did not succeed.

    
asked by anonymous 12.07.2017 / 03:44

1 answer

3

You have misplaced the configuration class in place of the class that is the entity.

You're like this:

public virtual DbSet<ApostaEstadoMap> ApostaEstado { get; set; }

Switch to:

public virtual DbSet<ApostaEstado> ApostaEstado { get; set; }
    
12.07.2017 / 04:12