#Migrations
When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.
Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```
generates the following DDL:
```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```
Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: Hi Ernst, I'm not able to reproduce the column naming issue. If I define the following class and context: ``` using System.Data.Entity; namespace Repro { public class MyContext : DbContext { public DbSet<MyEntity> MyEntities { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>() .Property(e => e.Id) .HasColumnName("intMyCustomId"); } } public class MyEntity { public int Id { get; set; } public string Name { get; set; } } } ``` Then call Add-Migration I get the following migration scaffolded: ``` namespace ConsoleApplication17.Migrations { using System; using System.Data.Entity.Migrations; public partial class Test : DbMigration { public override void Up() { CreateTable( "dbo.MyEntities", c => new { intMyCustomId = c.Int(nullable: false, identity: true), Name = c.String(), }) .PrimaryKey(t => t.intMyCustomId); } public override void Down() { DropTable("dbo.MyEntities"); } } } ``` Which in turn generates the correct SQL: ``` CREATE TABLE [dbo].[MyEntities] ( [intMyCustomId] [int] NOT NULL IDENTITY, [Name] [nvarchar](max), CONSTRAINT [PK_dbo.MyEntities] PRIMARY KEY ([intMyCustomId]) ) ``` ~Rowan
When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.
Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```
generates the following DDL:
```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```
Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: Hi Ernst, I'm not able to reproduce the column naming issue. If I define the following class and context: ``` using System.Data.Entity; namespace Repro { public class MyContext : DbContext { public DbSet<MyEntity> MyEntities { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>() .Property(e => e.Id) .HasColumnName("intMyCustomId"); } } public class MyEntity { public int Id { get; set; } public string Name { get; set; } } } ``` Then call Add-Migration I get the following migration scaffolded: ``` namespace ConsoleApplication17.Migrations { using System; using System.Data.Entity.Migrations; public partial class Test : DbMigration { public override void Up() { CreateTable( "dbo.MyEntities", c => new { intMyCustomId = c.Int(nullable: false, identity: true), Name = c.String(), }) .PrimaryKey(t => t.intMyCustomId); } public override void Down() { DropTable("dbo.MyEntities"); } } } ``` Which in turn generates the correct SQL: ``` CREATE TABLE [dbo].[MyEntities] ( [intMyCustomId] [int] NOT NULL IDENTITY, [Name] [nvarchar](max), CONSTRAINT [PK_dbo.MyEntities] PRIMARY KEY ([intMyCustomId]) ) ``` ~Rowan