MySqlException .NET Core 2.1: Unknown column 'xxxx' in 'field list'

0

I have a bizarre error that I would like to share with you.

I'm using Visual Studio 2017 and creating an MVC application with NET Core 2.1, based on a MySQL database and tables that already existed previously.

I created a model called Result and created the Annotations to correctly link to the table and the database. However, after the class was created, I decided to rename the columns in the table. Of course, I've also changed the Annotations to reflect the changes correctly.

However, when I make a query to this table, the application returns error saying that the xxxxxx column (and there shows the old column name) does not exist in the table, but I changed its name in the database and changed the class , but recompilation is not reflecting this change.

To make it clear, I'll leave the class code just below:

[Table("ProvasResultados")]
public class Resultado
{

    public Resultado() { }

    [Key]
    [Column("Ano")]
    public int Ano { get; set; }

    [Key]
    [Column("Prova")]
    public int ProvaId { get; set; }

    [Key]
    [Column("Atleta")]
    public int AtletaId { get; set; }

    [Key]
    [Column("Grupo")]
    public int GrupoId { get; set; }

    [Key]
    [Column("Atividade")]
    public int AtividadeId { get; set; }

    [Key]
    [Column("Tentativa")]
    public byte Tentativa { get; set; }

    [Column("Tempo")]
    public Nullable<System.TimeSpan> TempoRegistrado { get; set; }

    [Column("Indice")]
    public Nullable<decimal> IndiceRegistrado { get; set; }

    [Column("Pontuacao")]
    public Nullable<bool> Pontuacao { get; set; }

    [Column("MelhorDoDia")]
    public Nullable<bool> MelhorDoDia { get; set; }

    [Column("MelhorDoAno")]
    public Nullable<bool> MelhorDoAno { get; set; }

    [Column("RecordePessoal")]
    public Nullable<bool> RecordePessoal { get; set; }

    [ForeignKey("Ano, GrupoId, AtividadeId")]
    public AtividadePorGrupo GrupoAtividade { get; set; }

    [ForeignKey("Ano, ProvaId")]
    public Prova Prova { get; set; }

    [ForeignKey("Ano, ProvaId, AtletaId")]
    public Inscricao Inscricao { get; set; }
}

However, when the MVC will "mount the select" to retrieve the data from the table, I noticed in the error panel that the select is as below

SELECT p.Ano, p.Prova, p.Atleta, p.Grupo, p.Atividade, p.Tentativa, p.IndiceAno, p.IndiceId, p.Indice, p.MelhorDoAno, p.MelhorDoDia, p.Pontuacao, p.RecordePessoal, p.Tempo
FROM ProvasResultados AS p
WHERE (p.Ano = @__Ano_0) AND (p.Prova = @__Prova_1)

And the error:

  

MySql.Data.MySqlClient.MySqlException (0x80004005): Unknown column   'p.IndexAno' in 'field list

Where the "BestNew" column is now the old "IndexNear". That is, the MVC is not reflecting the changes in the class I'm determining.

Remembering that this is my first time with .NET Core 2.1, so I'm picking up a little, I'd like to know if anyone can help me with this problem.

Thanks in advance for all your help

    
asked by anonymous 26.12.2018 / 22:17

0 answers