views:

37

answers:

4

Hello, i have an existing DB with which i would like to build a new app using EF4.0

Some tables have not primary keys defined, so that when i create a new Entity Data Model i get the following message: "The table/view TABLE_NAME does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it".

If i want to use them and modify data can i necessarily add a PK to those tables or does it exist a workaround?

Thanks in advance ! c.

+4  A: 

The error means exactly what it says.

Even if you could work around this, trust me, you don't want to. The number of confusing bugs that could be introduced is staggering and scary, not to mention the fact that your performance will likely go down the tubes.

Don't work around this. Fix your data model.

Dave Markle
+4  A: 

Don't try and work around it... just create the primary key, EF Needs it.

Dusty Roberts
A: 

The above answers are correct if you really don't have a PK.

But if there is one but it is just not specified with an index in the DB, and you can't change the DB (yes, i work in Dilbert's world) you can manually map the field(s) to be the key.

Poker Villain
A: 

EF does not require a primary key on the database. If it did, you couldn't bind entities to views.

You can modify the SSDL (and the CSDL) to specify a unique field as your primary key. If you don't have a unique field, then I believe you are hosed. But you really should have a unique field (and a PK), otherwise you are going to run into problems later.

Erick

Erick T