Funky
Funky

Reputation: 13602

Entity Framework : Invalid Column after removing the column

I have a table mapped in Entity Framework which works great adding/updating and deleting records. I removed a column from SQL sever called "Category", then re-mapped my entity in the model. This worked fine, the column disappeared.

Now, I run a query on the table to update a row and get the same error, invalid column "Category".

This has been removed from the SQL table and removed from the Entity, so is it still looking for this damn column when I run the following code??

using (Entities db = new Entities())
                { 
                       var Voucher = (from vouchers in db.Vouchers
                                 where vouchers.ID == ID
                                 select vouchers).FirstOrDefault();

                       if (Voucher != null)
                       {
                           Voucher.Status = (int)Vouchers.UI.Enums.VoucherStatus.Removed;                           
                           ret = db.SaveChanges() == 1;
                       }
                } 

Here is the error:

Invalid column name 'Category'.

I have cleaned the code, built, re-built, and updated the enitties about a 100 times.

Does anyone have any ideas?

Thanks

Upvotes: 14

Views: 21052

Answers (6)

Mohd Aasif
Mohd Aasif

Reputation: 9

enter image description here

Open Edmx -> Right click on table column -> Choose Delete from Model

Upvotes: 0

yW0K5o
yW0K5o

Reputation: 943

Another solution is to locate the table in the Entity Framework diagram then delete the "Category" column and save the model file.

Upvotes: 0

LKC
LKC

Reputation: 186

I also came across the same which i solved by deleting the column from design view .edmx file. Other option is what mentioned earlier in the post that you remove the table and re-add that to your .edmx file.

Upvotes: 2

Oleg Sh
Oleg Sh

Reputation: 9013

not necessary to remove the whole table from *.EDMX file, just remove the unnecessary field from *.EDMX file. It helped me

Upvotes: 5

Petr J
Petr J

Reputation: 194

I used to also remove and re-add table, but never like this. What I rather do. I close model. right click and open as XML and them manually remove this reference. So it keeps my multiple diagrams within one model same and also my defined colors.

Upvotes: 10

JohnnBlade
JohnnBlade

Reputation: 4327

Remove the table from the *.EDMX file, and then add that table again to the *.EDMX file

Upvotes: 25

Related Questions