EF通过一种关系生成两个FK

时间:2015-05-17 09:35:24

标签: entity-framework-6

EF 6.1.3

映射

        var b = mb.Entity<PAYMENT_INVOICE>();
        b.ToTable("T_PAYMENT_INVOICE");
        b.HasPrimaryKey(x => x.Id);
        b.Property(x => x.OrdersSumm).IsRequired();
        b.Property(x => x.MargaSumm).IsRequired();
        b.Property(x => x.DeliverySumm).IsRequired();
        b.Property(x => x.PaySumm).IsRequired();
        b.Property(x => x.CreateDate).IsRequired();
        b.Property(x => x.Sended).IsRequired();
        b.Property(x => x.LastError).IsOptional();

        b.HasOptional(x => x.Payment).WithMany(x => x.Invoices).HasForeignKey(x => x.PaymentId);
        b.HasRequired(x => x.Client).WithMany().HasForeignKey(x => x.ClientId);
        b.HasRequired(x => x.Purchase).WithMany(x => x.Invoices).HasForeignKey(x => x.PurchaseId).WillCascadeOnDelete(false);

为什么要生成此密钥和列?两者都是平等的。

enter image description here

我删除了列PURCHASE_IDFK_dbo.T_PAYMENT_INVOICE_dbo.T_PURCHASE_PURCHASE_Id

当我保存PAYMENT_INVOICE时出现错误:

  

无效的列名称'PURCHASE_Id'

我不需要第二把钥匙,我的错误是什么?

0 个答案:

没有答案