Entity Framework "Invalid Column Name"

ef-code-first entity-framework


We have converted an existing DB to use EF, so we write classes to map to our tables. I've added a new column, a nullable int called 'iframeVideoId'. I mapped it with

public int? iframeVideoId { get; set; }

and when I do a search of that table, it blows up with an '

invalid column name' error

. This is a simple property it's not an index or related to any other table. I tried renaming it in the DB to 'DisplayVideo', and also making it not nullable. Then I had

public int iframeVideoId { get; set; }

Now I get an error that DisplayVideo is not a valid column. Of course I have double checked that I am pointing to the right DB, and confirmed that every DB that my code COULD point to, has this column. I've also done a clean and rebuild all, and rebooted my machine. What could be wrong ? This is a basic column, and it's there. I know from past experience that if the types did not match ( they are both int ), I'd get an error related to failed conversion between types. This makes no sense to me at all. I do not have an edmx file to refresh, because we're writing classes to map to the DB directly

Just to add, I changed the column to a string and it makes no difference. This is a new column, with a simple value, and EF claims it's not there.

And, I added the column to another table ( suboptimal, obviously ) and it just plain worked, immediately. I'd still like to know why I have a table I can't add columns to in EF, though

6/2/2014 10:39:27 PM

Popular Answer

I had an error in my mapping class from copy/paste situation. As you can see, mapped TranferredToEVP to 3 different columns. I was getting an "invalid column name" on the last column TranferredToGUID but was looking 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");
6/2/2014 10:35:04 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow