Linq – How to get the table back after I remove it from the EDMX file in Linq-to-Entities

edmxlinq-to-entitiesupdatemodel

I am having trouble with my Linq2Entities model – I might be missing something obvious here.

Here is what I did:

  • Added an EDMX model file
  • Added TableX to the model
  • Went back to SQL Management Studio and updated TableX, changing its primary key
  • Went back to my EDMX file and click "Update Model from Database"
  • TableX updated but incorrectly, not reassigning the new primary key
  • I then deleted TableX from my model
  • Click "Update Model from Database"
  • TableX is now in the "Add" tab, but still in the "Refresh" tab
  • I click on the "Refresh" tab and click "Finish"
  • TableX does not reappear

If I repeat this process in a new project with a different database and (obviously) a different table it still happens.

Why can't I get my table back in the model?!

Best Answer

This to me is horrible part of LINQ-to-Entities. If I'm smart and remember I usually don't close the edmx files while editing it. I then undo changes until I get back to working version. Otherwise,

  1. Open the edmx file with the XML editor and manually inspect and remove all references to the table that is not "reappearing".
  2. Curse because doing this is a real pain (but works).
  3. Build to make sure you removed all the references correctly.
  4. Update the model from database again.
Related Topic