Entity framework Invalid Column name, EF adds number 1 to primary key

I received this error in relation to a non-foreign key column and wasted far too much time trying to figure out the error. It was in my code, not in EF or the database. I had simply thought that I had typed

this.Property(t => t.Revision).HasColumnName("Revision");
this.Property(t => t.DistributionClass).HasColumnName("DistributionClass");

But what I had typed was

this.Property(t => t.Revision).HasColumnName("Revision");
this.Property(t => t.Revision).HasColumnName("DistributionClass");

I suppose I was looking at the line above and put t.Revision instead of t.DistributionClass. And no matter how long I looked at it I could not see my own mistake. With any luck this will save some other poor soul some time.


Try add a many-to-one mapping as well. Please use pure Fluent API, and you should remove the [ForeignKey] annotations.

modelBuilder.Entity<Publicacion>()
            .HasRequired(x => x.Suscriptores)
            .WithMany(x => x.Publicacion);

Hello Guys In my case I had a legacy code with two classes with different names of the same foreign key. Adding the Annotation doing reference to the correct column and the name of attribute with the same name in other classes.then the annotation ForeignKey doing match between the both columns.

[Table("LFile")]
public partial class LFile
{
    [Key]
    public int FileId { get; set; }

    [StringLength(500)]
    public string FileName { get; set; }

    public int? LRRFileDetailId { get; set; }

    public byte[] FileData { get; set; }

    public FileType Type { get; set; }

    [Column("LUpload_Id")] //Foreign Key of the class
    public int? LUploadId { get; set; }

    [ForeignKey("LUploadId")] //Foreign key inherited
    public virtual LParserProcess LParserProcess { get; set; }
}

I had this issue in my Item table on a property (column) I had just added, and how frustrating!

Turns out I had a List property in the data model for Order, and because I did not Ignore it in that configuration it cause this same issue in the Item table. This would not have happened except that both tables had a property of the same name, so I had to do this... which I should have done anyways.

public OrderConfiguration() { Ignore(p => p.Items); }