【发布时间】:2014-10-08 13:45:36
【问题描述】:
EF Migrations 似乎无法检测到我对模型所做的更改,因为它在运行 Add-Migration 时只会生成一个空的 Up() / Down()。
数据库与我的迁移没有不同步。
迁移文件:
__migrationhistory 表:
之前
public class House {
public virtual ICollection<Person> UsedBy { get; set; }
}
public class Car {
// ...
}
public class Person {
public int? UsingId { get; set; }
public virtual House Using { get; set; }
}
映射
this.HasOptional(t => t.Using)
.WithMany(t => t.UsedBy)
.HasForeignKey(t => t.UsingId);
之后
public class House {
// removed
}
public class Car {
// added
public virtual ICollection<Person> UsedBy { get; set; }
}
public class Person {
public int? UsingId { get; set; }
// changed type
public virtual Car Using { get; set; }
}
映射
this.HasOptional(t => t.Using)
.WithMany(t => t.UsedBy)
.HasForeignKey(t => t.UsingId);
【问题讨论】:
-
我可以确认这个问题。重命名
Using属性是一个有效的“解决方案”。也许这是 EF 中的一个错误...
标签: c# entity-framework ef-code-first entity-framework-migrations