Entity Framework "Invalid column name"

We converted the existing database to use EF, so we are writing classes to map to our tables. I added a new column with a null int called iframeVideoId. I matched it with

public int? iframeVideoId { get; set; } 

and when I search for this table, it explodes with

invalid column name error

. This is a simple property that is not an index or is associated with some other table. I tried to rename it in the database to " DisplayVideo ", and also make it invalid. Then I had

 [Column("DisplayVideo")] public int iframeVideoId { get; set; } 

Now I get an error that DisplayVideo is not a valid column. Of course, I double-checked that I was pointing to the correct database, and confirmed that each database that my code MAY indicate indicates this column. I also did a clean and restored everything, and rebooted my machine. What could be wrong? This is the base column, and it is. I know from past experience that if the types do not match (they are both int), I would get an error related to the unsuccessful conversion between types. It makes no sense to me at all. I do not have an edmx file to update because we are writing classes to directly bind to the database

Just to add, I changed the column to a row, and that doesn't make any difference. This is a new column with a simple value, and EF claims it is not.

And I added the column to another table (suboptimal, obviously), and it just worked, right away. I would still like to know why I have a table to which I cannot add columns in EF, although

+7
source share
2 answers

I had an error in my mapping class from a copy / paste situation. As you can see, TranferredToEVP is mapped to three different columns. I got an invalid column name in the last column of TranferredToGUID, but searched for TranferredToGUID1. Hope this helps.

 this.Property(t => t.TransferredToEVP).HasColumnName("TransferredToEVP"); this.Property(t => t.TransferredToEVP).HasColumnName("TransferredToName"); this.Property(t => t.TransferredToEVP).HasColumnName("TransferredToGUID"); 
+2
source

I had the same problem as Amy Jonas, if you thought it, make sure that the display is correct.

My code looked like this:

 Property(d => d.LastUpdatedOn).HasColumnName("LastUpdatedOn"); Property(d => d.LastUpdatedOn).HasColumnName("LastUpdatedBy"); 

It should be:

 Property(d => d.LastUpdatedOn).HasColumnName("LastUpdatedOn"); Property(d => d.LastUpdatedBy).HasColumnName("LastUpdatedBy"); 

Sometimes we get too busy and we forget to look at these details.

0
source

All Articles