1

I am using Entity Framework database First approach

I have a table having composite primary key on ID(int ,identity increment), HashKey (binary) auto generated based on multiple columns using sql hashbytes.

Following is EF Column Mapping

ID storeGeneratedPattern="Identity" and hashkey(binary) storeGeneratedPattern="Computed".

When i try to save using EF save changes method it is throwing below exception.

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

I have applied composite primary key on these columns(Id,Hashkey) to make search faster as it contains cluster index. But not sure whether EF supports this.

I have seen below link. But i am not sure about the solution.

Property with StoreGeneratedPattern set to Identity is not updted after SaveChanges()

Can anybody help on this to resolve the issue.

Community
  • 1
  • 1
Chandra Mohan
  • 729
  • 2
  • 10
  • 29

1 Answers1

0

'Computed' means EF expects SQL to generate the value after every insert/update. Therefore it doesn't make sense for it to be part of the PK.

You can just leave the identity as the PK and still create a clustered index with columns(id, hash).

Having said that, it also doesn't make sense to include a computed column in a clustered index. Every time the computed column is changed, the entire row needs to be moved to the new position.

user2880486
  • 1,068
  • 7
  • 16