我有两个模型
public class Employee
{
public Employee()
{
Active = true;
}
[Key]
public long Id { get; set; }
public List<Service> Services { get; set; }
public List<SubService> SubServices { get; set; }
[NotMapped]
public List<long> ServiceIds { get; set; }
public bool IsSyncedToSP { get; set; }
public Certificate Certificate { get; set; }
[NotMapped]
public List<long> SubServiceIds { get; set; }
public List<long> GetServiceIds()
{
if (ServiceIds != null && ServiceIds.Count > 0)
{
return ServiceIds;
}
else if (Services != null && Services.Count > 0)
{
return Services.Select(s => s.Id).ToList();
}
return new List<long>();
}
和
public class Certificate
{
[Key]
public long Id { get; set; }
[Required]
[UnsyncOnEdit(Unsync = true)]
public string Title { get; set; }
public bool IsSyncedToSP { get; set; }
public List<Employee> Employees { get; set; }
}
当我尝试public List<Employee> Employees { get; set; }将此关系添加到证书模型并尝试添加迁移时,EF 创建以下迁移
public partial class empcert2 : DbMigration
{
public override void Up()
{
RenameTable(name: "dbo.ServiceClients", newName: "ClientServices");
RenameTable(name: "dbo.EmployeeServices", newName: "ServiceEmployees");
DropPrimaryKey("dbo.ClientServices");
DropPrimaryKey("dbo.ServiceEmployees");
AddPrimaryKey("dbo.ClientServices", new[] { "Client_Id", "Service_Id" });
AddPrimaryKey("dbo.ServiceEmployees", new[] { "Service_Id", "Employee_Id" });
}
迁移尝试重命名现有表,当我运行它时,它给出 errno:2 no such file found 错误。
如果我public List<Employee> Employees { get; set; }从证书模型中删除此行,则不会创建奇怪的迁移。
任何想法为什么会发生这种情况
米脂
相关分类