Search code examples
entity-frameworkfluent

Entity Framework FluentAPI naming the Primary Key


By convention, EF generates "PK_<<Schema>>.<<TableName>>" as the backing index name for an entity primary key.

Call me a control-freak, but I like providing specific names for my primary keys, and I've been unable to locate any specific annotation or FluentAPI syntax which permits overriding the default behavior.

Am I missing something, or is this simply unavailable?

Thanks.


Solution

  • In EF6.x you can do this by specifying a name in your migrations. The scaffolded migrations don't include a name (and therefore use a default convention) but you can edit the code to specify another name.

    In EF7, all database objects will have a name specified in the model, so you won't need to drop down to Migrations to specify the names.