I have a class similar to
public class Foo
{
public virtual string Bar { get; set; }
}
Now we need to consider it Baras a CHAR (8), so I changed the property to
[StringLength(8)]
[Column(TypeName = "char")]
public virtual string Bar { get; set; }
There are many migrations in a project, usually adding new classes or new properties to existing classes. I know that I can just create a new migration that will change the type of the column, but seemed a bit confusing, to first create the column as NVARCHAR (Max) and then change it to CHAR (8). I edited the initial migration, changing
CreateTable(
"dbo.Foo",
c => new
{
Bar = c.String(),
})
to
CreateTable(
"dbo.Foo",
c => new
{
Bar = c.String(maxLength: 8, fixedLength: true, storeType: "char", unicode: false),
})
Then I deleted the database and ran a program that used the context, thereby recreating the database.
, . , Foo CHAR (8). , AutomaticMigrationsDisabledException.
, , EF,
public override void Up()
{
AlterColumn("dbo.Foo", "Bar", c => c.String(maxLength: 8, fixedLength: true, unicode: false));
}
public override void Down()
{
AlterColumn("dbo.Foo", "Bar", c => c.String());
}
Up() , , ( ), Down() NVARCHAR (Max), .
EF , , , NVARCHAR (Max), CHAR (8) ?