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
Post a Comment