Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# postgresql多对多映射返回错误_C#_Postgresql_Visual Studio_Entity Framework_Asp.net Core - Fatal编程技术网

C# postgresql多对多映射返回错误

C# postgresql多对多映射返回错误,c#,postgresql,visual-studio,entity-framework,asp.net-core,C#,Postgresql,Visual Studio,Entity Framework,Asp.net Core,嗨,我正在寻找一些关于我当前映射的有用提示。当我尝试添加迁移时,它返回以下错误。我不太确定我做错了什么,或者这不是我应该如何绘制它们的 System.Reflection.TargetInvocationException:已引发异常 通过调用的目标。-->System.InvalidOperationException: 无法在“Brokers.ManifestToBrokers”和之间创建关系 “ManifestToBroker.ACASBroker”,因为已经有关系了 在“Brokers.

嗨,我正在寻找一些关于我当前映射的有用提示。当我尝试添加迁移时,它返回以下错误。我不太确定我做错了什么,或者这不是我应该如何绘制它们的

System.Reflection.TargetInvocationException:已引发异常 通过调用的目标。-->System.InvalidOperationException: 无法在“Brokers.ManifestToBrokers”和之间创建关系 “ManifestToBroker.ACASBroker”,因为已经有关系了 在“Brokers.ManifestToBrokers”和“ManifestToBroker.ABIBroker”之间。 导航属性只能参与单个关系

我有3张表,清单,清单经纪人,经纪人

public class Manifest
{
    public virtual ManifestToBroker ManifestToBroker { get; set; }
    .......other stuff
}

public class ManifestToBroker
{
    public virtual Manifest Manifest { get; set; }

    public int ManifestId { get; set; }

    public int? ABIFilerId { get; set; }

    public int? ACASFilerId { get; set; }

    public int? AMSFilerId { get; set; }

    public virtual Brokers ABIBroker { get; set; }

    public virtual Brokers ACASBroker { get; set; }

    public virtual Brokers AMSBroker { get; set; }
}

public class Brokers
{
    [StringLength(32)]
    [Required(AllowEmptyStrings = false)]
    public string Name { get; set; }

    [StringLength(50)]
    public string Description { get; set; }

    [StringLength(100)]
    public string Contacts { get; set; }

    [Required]
    public int BrokerType { get; set; }

    [Required]
    public bool SupportABI { get; set; }

    [Required]
    public bool SupportACAS { get; set; }

    [Required]
    public bool SupportAMS { get; set; }

    public virtual ICollection<ManifestToBroker> ManifestToBrokers { get; set; } = new List<ManifestToBroker>();
}
公共类清单
{
公共虚拟ManifestToBroker ManifestToBroker{get;set;}
……其他东西
}
公共类声明代理
{
公共虚拟清单清单{get;set;}
公共int ManifestId{get;set;}
公共int?ABIFilerId{get;set;}
公共int?ACASFilerId{get;set;}
public int?AMSFilerId{get;set;}
公共虚拟代理程序ABIBroker{get;set;}
公共虚拟代理ACASBroker{get;set;}
公共虚拟代理AMSBroker{get;set;}
}
公营经纪
{
[条次建议修正案(32)]
[必需(AllowEmptyStrings=false)]
公共字符串名称{get;set;}
[长度(50)]
公共字符串说明{get;set;}
[长度(100)]
公共字符串联系人{get;set;}
[必需]
public int BrokerType{get;set;}
[必需]
公共布尔支持BI{get;set;}
[必需]
公共bool支持cas{get;set;}
[必需]
公共布尔支持ms{get;set;}
公共虚拟ICollection ManifestToBrokers{get;set;}=new List();
}
为了简单起见,我将所有映射都放在ManifestToBrokerMapper中

public class ManifestToBrokerMapping : IntKeyBaseBaseEntityConfiguration<ManifestToBroker>
{
    protected override void ConfigureThis(EntityTypeBuilder<ManifestToBroker> builder)
    {
        builder.HasKey(m => m.Id);
        builder.HasOne(m => m.ABIBroker)
            .WithMany(m => m.ManifestToBrokers)
            .HasForeignKey(m => m.ABIFilerId);
        builder.HasOne(m => m.ACASBroker)
            .WithMany(m => m.ManifestToBrokers)
            .HasForeignKey(m => m.ACASFilerId);
        builder.HasOne(m => m.AMSBroker)
            .WithMany(m => m.ManifestToBrokers)
            .HasForeignKey(m => m.AMSFilerId);
        builder.HasOne(m => m.Manifest)
            .WithOne(m => m.ManifestToBroker)
            .IsRequired();
        builder.HasIndex(m => new { m.ManifestId, m.ABIFilerId }).IsUnique();
        builder.HasIndex(m => new { m.ManifestId, m.ACASFilerId }).IsUnique();
        builder.HasIndex(m => new { m.ManifestId, m.AMSFilerId }).IsUnique();
    }
}
公共类ManifestToBrokerMapping:IntKeyBaseEntityConfiguration
{
受保护的覆盖无效配置信息(EntityTypeBuilder)
{
builder.HasKey(m=>m.Id);
builder.HasOne(m=>m.ABIBroker)
.有许多(m=>m.ManifestToBrokers)
.HasForeignKey(m=>m.ABIFilerId);
builder.HasOne(m=>m.ACASBroker)
.有许多(m=>m.ManifestToBrokers)
.HasForeignKey(m=>m.ACASFilerId);
builder.HasOne(m=>m.AMSBroker)
.有许多(m=>m.ManifestToBrokers)
.HasForeignKey(m=>m.AMSFilerId);
builder.HasOne(m=>m.Manifest)
.WithOne(m=>m.ManifestToBroker)
.IsRequired();
HasIndex(m=>new{m.ManifestId,m.ABIFilerId}).IsUnique();
HasIndex(m=>new{m.ManifestId,m.ACASFilerId}).IsUnique();
HasIndex(m=>new{m.ManifestId,m.AMSFilerId}).IsUnique();
}
}

找到问题,Brokers表还需要包含每个ManifestToBroker

public virtual ICollection<ManifestToBroker> ABIFilerMTB { get; set; } = new List<ManifestToBroker>();

public virtual ICollection<ManifestToBroker> ACASFilerMTB { get; set; } = new List<ManifestToBroker>();

public virtual ICollection<ManifestToBroker> AMSFilerMTB { get; set; } = new List<ManifestToBroker>();
公共虚拟ICollection ABIFilerMTB{get;set;}=new List(); 公共虚拟ICollection ACASFilerMTB{get;set;}=new List(); 公共虚拟ICollection AMSFilerMTB{get;set;}=new List();