Code First Migrations - Incorrect Column Nullablity
Posted: Thu 09 Feb 2012 14:21
I have the following entity:
With the following configuration:
The following migration is generated:
Which generated the following SQL
Notice that DelatedAt is created as not null when its listed in the configuration as optional and not set as nullable in the migration.
Is this a bug or am I doing something wrong?
Code: Select all
public class MyEntity
{
public long Id { get; set; }
public DateTime? DeletedAt { get; set; }
}
Code: Select all
public class MyEntityConfiguration : EntityTypeConfiguration
{
public MyEntityConfiguration()
{
HasKey(m => m.Id);
Property(m => m.Id)
.HasColumnName("Id")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(m => m.DeletedAt)
.IsOptional();
}
}
Code: Select all
public class MyMigration : DbMigration
{
public override void Up()
{
CreateTable(
"MyEntities",
c => new
{
Id = c.Long(nullable: false, identity: true),
DeletedAt = c.DateTime(),
})
.PrimaryKey(t => t.Id);
}
public override void Down()
{
DropTable("MyEntities");
}
}
Code: Select all
CREATE TABLE "MyEntities" (
"Id" NUMBER(18) NOT NULL,
"DeletedAt" TIMESTAMP NOT NULL,
PRIMARY KEY ("Id")
)
CREATE SEQUENCE "MyEntities_SEQ"
CREATE OR REPLACE TRIGGER "MyEntities_INS_TRG"
BEFORE INSERT ON "MyEntities"
FOR EACH ROW
BEGIN
SELECT "MyEntities_SEQ".NEXTVAL INTO :NEW."Id" FROM DUAL;
END;
Is this a bug or am I doing something wrong?