c# - Entity framework Key attribute is not setting column as identity -


i have following:

public class fieldbookingmessagethread : messagethread, isoftdeletable, itimestamps, icreatedby {     [key, databasegenerated(databasegeneratedoption.identity)]     public int fieldbookingmessagethreadid { get; set; } } 

there nothing of interest in messagethread class.

when run data migration package manager console, not seem put identity:true on column.

i have created custom data migration column:

altercolumn( "dbo.fieldbookingmessagethreads", "fieldbookingmessagethreadid", c => c.int( nullable: false, identity: true ) ); 

it runs fine no errors not change column identity?

what might doing wrong?

quick solution not correct one:

i have had remove migrations. create fresh new migration. delete database, run migration... , seems okay. i've kept old migrations in case, sounds bug?

you need set [databasegenerated(databasegeneratedoption.identity)] attribute

public class fieldbookingmessagethread : messagethread, isoftdeletable, itimestamps, icreatedby {     [key]     [databasegenerated(databasegeneratedoption.identity)]     public int fieldbookingmessagethreadid { get; set; } } 

or

public class fieldbookingmessagethread : messagethread, isoftdeletable, itimestamps, icreatedby {     [key, databasegenerated(databasegeneratedoption.identity)]     public int fieldbookingmessagethreadid { get; set; } } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -