Getting Invalid column name 'CompanyLocationId' in entity framework .net core

Viewed 81

From database I removed column company_location_id from table named Company. Then I removed property CompanyLocationId from model class. But I am getting above error.

 public DbSet<Company> Company { get; set; }

Above property I set in DBContext class.

  //[Column("company_location_id")]
    //[ForeignKey(nameof(CompanyLocation))]
    //public int? CompanyLocationId { get; set; }

    [Column("created_by")]
    [ForeignKey(nameof(AppUser))]
    public int CreatedBy { get; set; }

    [Column("creation_date")]
    public DateTime CreationDate { get; set; }

I commented above property because it I removed that column from table.

But while getting from data from company table then I am getting above error. FYI I am using repository design pattern and entity framework.

1 Answers

VR, You just commented on your property from the DBContext class, but when you open your ADO.NET Entity Data Model (.edmx) file, you will see still that particular column is there in that particular table.

You can do:

  1. Update your (.edmx) file by refreshing the table from your database.

  2. Remove all entities from your Entity Data Model (.edmx) file and add it again from your database.

For more information regarding the (.edmx) file, you can read my article How to create an ADO.NET Entity Data Model (EDM)

I hope this will work for you.

Related