Reputation: 812
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
[Column("DisplayVideo")]
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
Upvotes: 8
Views: 22066
Reputation: 742
I had the same issue like Amy Jonas had, if you happen to come across this, make sure the mapping is correct.
My code looked like this before :
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 that we forget to look at these details.
Upvotes: 0
Reputation: 21
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");
Upvotes: 2