I am a bit mystified by some Entity Framework behavior. I have a class like this:
Account
-ID (PK, int, not null)
-AccountID (PK, int, not null)
-ClientID
-... other scalars
The AccountID field should come from an API we consume. Unfortunately, I did not know at the time that Entity Framework does not support non-db generated primary keys. So I have to drop the AccountID as part of the primary key.
When I remove the [Key] attribute from the AccountID field, I get some odd behavior from the migration. Here are the lines from the migration which make no sense to me.
DropColumn("dbo.Account", "ClientID");
RenameColumn(table: "dbo.Account", name: "ID", newName: "ClientID");
.... more stuff
AlterColumn("dbo.Account", "ID", c => c.Int(nullable: false, identity: true));
AddPrimaryKey("dbo.Account", "ID");
Why would Entity Framework be trying to drop this unrelated column (ClientID)? And why is it trying to use a column in the AlterColumn statement which no longer exists (ID has been renamed to ClientID)?