Mithrilhall
Mithrilhall

Reputation: 1502

Save entity in Entity Framework without a primary key

Scenario:

Database first. I have a table with no primary key set and I'm trying to make an update with Entity Framework.

This is the error message I keep getting:

The property 'inactive_date' is part of the object's key information and cannot be modified. 

If I set the fields 'Entity Key' value to 'false' I get this error messge:

Modifications to tables where a primary key column has property 'StoreGeneratedPattern' set to 'Computed' are not supported. Use 'Identity' pattern instead. Key column: 'timestamp'. Table: 'plat12Model.Store.glchart'.

Would this be corrected if I created a primary key? Can I set a primary key in my code rather than on the database?

Upvotes: 1

Views: 2423

Answers (1)

Jim Wooley
Jim Wooley

Reputation: 10398

By default, EF will make tables without primary keys and views into read-only classes where every field is part of the composite key. You can modify the conceptual model to reflect the actual behavior as long as you retain a key value that EF will use for object tracking. As the error message states, you also need to make the columns no longer computed in order to update them as well.

Upvotes: 1

Related Questions