[英]Column names in each table must be unique. Column name 'LastName' in table 'HumanCustomers' is specified more than once
[英]Column names in each table must be unique. Column name 'Id' in table Entity1' is specified more than once
想法是将nameof用作外键,因为如果更改属性名的编译器会捕获到此,则我将永远不会忘记更改外键依赖项
public class Entity1 {
[Key]
public int Id { get; set; }
public int OtherId { get; set; }
[Foreign Key(nameof(OtherId))]
public virtual Entity2 Entity { get; set; }
}
public Entity2 {
[Key]
public int Id {get;set;}
public string Name {get;set;}
}
当我尝试从迁移中更新数据库时,出现主题错误。 我在这里做错什么了吗? 问候,
您已经在该类的同一个类中拥有一个属性。 尝试更改外键名称,例如:
[ForeignKey("name of foreign key here")]
public virtual Entity2 Entity { get; set; }
看到:
你可以试试这个
public class Entity1
{
[Key]
public int Id { get; set; }
[ForeignKey("Entity2")]
public int Entity2ID { get; set; }
public virtual Entity2 Entity2 { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.