With Entity Framework, whenever I “update model from database” inside Visual Studio the model that’s created isn’t usable.
The issue is that EF doesn’t handle tables without a primary key very well. It treats them as a view, which in turn prevents you from editing the table with EF. You can override this behavior by opening the model (edmx file) as an XML file and making a few changes to the EntitySet definition. It’s annoying to do this over and over. Has anyone found a more permanent workaround besides adding a primary key or modifying the edmx file after every update?
By the way, I am using a unique key but it’s spread across two columns. It’d be nice if EF could handle this, but as of EF 4.2 it doesn’t.
I don’t understand – you’re using a “unique key” (I assume you mean a unique index or a unique constraint) because the key has two columns? You can create a primary key with multiple columns. I’m not sure why EF would treat a two-column key differently than a single-column primary key, but here is a simple example of a multiple-column primary key:
Of course there is other syntax that allows you to create the constraint after the fact, and you should also name your constraint explicitly, but just wanted to show a simple example.