EF 迁移出现重复 属性 名称错误

Duplicate property name error with EF migration

我的 Agency 模型中定义了以下属性:

public int AgencyCapturedById { get; set; }
public User AgencyCapturedBy { get; set; }

当我尝试 运行 和 Add-Migration 命令时,出现以下错误:

AgencyCapturedById: Name: Each property name in a type must be unique. Property name 'AgencyCapturedById' is already defined.

首先,如果它已经在 class Agency 的其他地方定义,则项目将不会构建,然后搜索整个解决方案以查找文件类型 *.*,因为术语 AgencyCapturedById 只产生一个结果,即上面声明它的那一行。 EF 在哪里可以找到另一个相同的 属性 名称?它甚至不像我以前使用过它并删除它,所以它可能会在某个地方困扰我。

可能是因为覆盖了命名约定?例如,我可以使用以下代码生成此错误:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Properties()
                            .Where(p => p.Name == "Id")
                            .Configure(p => p.IsKey().HasColumnName(p.ClrPropertyInfo.ReflectedType == null ? "Id" : p.ClrPropertyInfo.ReflectedType.Name + "Id"));
}

public class Agency
{
    public int Id { get; set; }
    [Column("UserId")]
    public int UserId { get; set; }
    public User AgencyCapturedBy { get; set; }
}

[ComplexType]
public class User
{
    public int Id { get; set; }
}