我已经使用数据库优先方法在C#中创建了一些类,目前我正在重构这些类以使名称更易于阅读。
但是,更改属性名称并在ColumnAttribute
中应用原始属性仍然会导致迁移。
当我重命名其他实体/表引用的组合键时,这似乎适用。
例如,更改此:
[Key]
[Column("SCHED_NAME", Order = 0)]
[StringLength(120)]
public string SCHED_NAME { get; set; }
收件人:
[Key]
[Column("SCHED_NAME", Order = 0)]
[StringLength(120)]
public string SchedulerName { get; set; }
创建这样的迁移:
DropForeignKey("dbo.QRTZ_TRIGGERS", new[] { "SCHED_NAME", "JOB_NAME", "JOB_GROUP" }, "dbo.QRTZ_JOB_DETAILS");
CreateTable(
"dbo.QRTZ_TRIGGERS",
c => new
{
SCHED_NAME = c.String(nullable: false, maxLength: 120),
TRIGGER_NAME = c.String(nullable: false, maxLength: 150),
TRIGGER_GROUP = c.String(nullable: false, maxLength: 150),
JOB_NAME = c.String(nullable: false, maxLength: 150),
JOB_GROUP = c.String(nullable: false, maxLength: 150),
DESCRIPTION = c.String(maxLength: 250),
NEXT_FIRE_TIME = c.Long(),
PREV_FIRE_TIME = c.Long(),
PRIORITY = c.Int(),
TRIGGER_STATE = c.String(nullable: false, maxLength: 16),
TRIGGER_TYPE = c.String(nullable: false, maxLength: 8),
START_TIME = c.Long(nullable: false),
END_TIME = c.Long(),
CALENDAR_NAME = c.String(maxLength: 200),
MISFIRE_INSTR = c.Int(),
JOB_DATA = c.Binary(),
})
.PrimaryKey(t => new { t.SCHED_NAME, t.TRIGGER_NAME, t.TRIGGER_GROUP })
.ForeignKey("dbo.QRTZ_JOB_DETAILS", t => new { t.SCHED_NAME, t.JOB_NAME, t.JOB_GROUP });
CreateTable(
"dbo.QRTZ_JOB_DETAILS",
c => new
{
SCHED_NAME = c.String(nullable: false, maxLength: 120),
JOB_NAME = c.String(nullable: false, maxLength: 150),
JOB_GROUP = c.String(nullable: false, maxLength: 150),
DESCRIPTION = c.String(maxLength: 250),
JOB_CLASS_NAME = c.String(nullable: false, maxLength: 250),
IS_DURABLE = c.Boolean(nullable: false),
IS_NONCONCURRENT = c.Boolean(nullable: false),
IS_UPDATE_DATA = c.Boolean(nullable: false),
REQUESTS_RECOVERY = c.Boolean(nullable: false),
JOB_DATA = c.Binary(),
})
.PrimaryKey(t => new { t.SCHED_NAME, t.JOB_NAME, t.JOB_GROUP });
DropTable("dbo.QRTZ_TRIGGERS");
DropTable("dbo.QRTZ_JOB_DETAILS");
}
CreateTable
语句与初始语句相同。
为什么会发生这种情况?
答案 0 :(得分:0)
如果要使人类可读的名称出现在应用程序中,则需要在Column()属性内更改名称。上面您想要做的是更改列的实际名称。在下面检查我如何在Column()属性中将名称更改为所需名称,但保持原名称-
[Key]
[Column("SchedulerName", Order = 0)]
[StringLength(120)]
public string SCHED_NAME { get; set; }