【发布时间】:2021-10-01 07:12:29
【问题描述】:
您好,我需要帮助。
我正在使用 ASP.Net Core 3.0 和 EF Core... 我需要编辑一个具有导航属性的多对多表。
我尝试了下面的代码,我可以获取发票数据,但我在 ProductInvoices 属性上得到空值,该属性也是多对多关系表的链接。
// GET: Invoices/Edit
public async Task<IActionResult> Edit(int? id)
{
var invoice = await _context.Invoices.Where(i => i.InvoiceId == id).FirstOrDefaultAsync();
return View(invoice);
}
public class Product
{
[Key]
public int ProductId { get; set; }
public int ProductsItemInStock { get; set; }
public decimal CostPerItem { get; set; }
public string ItemName { get; set; }
public IList<ProductInvoice> ProductInvoices { get; set; }
}
public class Invoice
{
[Key]
public int InvoiceId { get; set; }
public DateTime CreatedDate { get; set; }
public Guid CreateByUser { get; set; }
public int TotalInvoice { get; set; }
public IList<ProductInvoice> ProductInvoices { get; set; }
}
public class ProductInvoice
{
[Key]
public int ProductId { get; set; }
public Product Product { get; set; }
[Key]
public int InvoiceId { get; set; }
public Invoice Invoice { get; set; }
}
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-core entity-framework-core