我希望表格PaintballWorker
,Invoices
和Receipts
与关系相关联。 PaintballWorker
可以包含多个Invoices
和AddedInvoices
,还可以有多个Receipts
和AddedReceipts
。 PaintballWorker
和Invoices
之间的关系适用于Invoices
和AddedInvoices
。我想对Receipts
做同样的事情,但我在更新数据库时遇到错误:
ALTER TABLE语句与FOREIGN KEY约束冲突 “FK_dbo.Receipts_dbo.PaintballWorkers_ReceiptAddedByID”。冲突 发生在数据库“1028_test”,表“dbo.PaintballWorkers”,列 'PaintballWorkerID'。
我的主要课程(PaintballWorker
):
public class PaintballWorker : Person
{
[Key]
public int PaintballWorkerID { get; set; }
(other properties)
[InverseProperty("PaintballWorker")]
public virtual List<Invoice> Invoices { get; set; }
[InverseProperty("InvoiceAddedBy")]
public virtual List<Invoice> AddedInvoices { get; set; }
[InverseProperty("PaintballWorker")]
public virtual List<Receipt> Receipts { get; set; }
[InverseProperty("ReceiptAddedBy")]
public virtual List<Receipt> AddedReceipts { get; set; }
}
我的Receipt
课程:
public class Receipt
{
[Key]
public int ReceiptID { get; set; }
(other properties)
public int PaintballWorkerID { get; set; }
[ForeignKey("PaintballWorkerID")]
public virtual PaintballWorker PaintballWorker { get; set; }
public int ReceiptAddedByID { get; set; }
[ForeignKey("ReceiptAddedByID")]
public virtual PaintballWorker ReceiptAddedBy { get; set; }
}
我的Invoice
课程:
public class Invoice
{
[Key]
public int InvoiceID { get; set; }
(other properies)
public int PaintballWorkerID { get; set; }
[ForeignKey("PaintballWorkerID")]
public virtual PaintballWorker PaintballWorker { get; set; }
public int InvoiceAddedByID { get; set; }
[ForeignKey("InvoiceAddedByID")]
public virtual PaintballWorker InvoiceAddedBy { get; set; }
}
有人可以解释这里有什么问题吗?
目前public virtual PaintballWorker PaintballWorker { get; set; }
Invoice
和Receipt
工作正常,使用public int InvoiceAddedByID { get; set; }
[ForeignKey("InvoiceAddedByID")]
public virtual PaintballWorker InvoiceAddedBy { get; set; }
更新了数据库
并且工作正常,但是当我想用数据库更新时
public int ReceiptAddedByID { get; set; }
[ForeignKey("ReceiptAddedByID")]
public virtual PaintballWorker ReceiptAddedBy { get; set; }
我收到的错误是我在开始时写的。