I suppose the title says it all. I have to change a table so that the ID PK column is no longer auto generated, so I can physically insert specific values.
Now the table is actually a composite key. Which is as follows;
[Key,Column("driverId", Order=0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public override int ID { get; set; }
[Key,Column("type", Order=1)]
[ForeignKey("DriverType")]
public int DriverTypeId { get; set; }
public virtual DriverType DriverType { get; set; }
Now I have added the DatabaseGenerated attribute and ran a migration which did create the following;
DropPrimaryKey("dbo.Driver");
AlterColumn("dbo.Driver", "driverId", c => c.Int(nullable: false));
AddPrimaryKey("dbo.Driver", new[] { "driverId", "type" });
i.e. the AlterColumn doesnt have the Identity bool in it.
However when I look at the make up of the table I have the following
CREATE TABLE [dbo].[Driver] (
[driverId] INT IDENTITY (1, 1) NOT NULL,
Am I safe to just removd the IDENTITY (1,1)?
To answer you question, no it is not safe to do that.
Add [DatabaseGenerated(DatabaseGeneratedOption.None)] to both parts of the key.