У меня только что возникла проблема с созданием Create API (метод POST) во многих отношениях. Я читал о том, как настроить отношение, но как его реализовать. Во всем примере дается составной ключ в таблице соединений, для меня таблица соединений имеет свой собственный ключ, так как я могу это сделать.
Также я видел этот вопрос, но я не понимаю, хочу ли я, чтобы viewModel содержал все поля счета-фактуры и продукта и сопоставлял их с основными классами или как Вставить новую запись в сводную таблицу с отношением «многие ко многим» с помощью Entity Framework Core
Invoice
public int InvoiceId { get; set; }
public DateTime InvoiceDate { get; set; }
public string InvoiceNote { get; set; }
public ICollection<CustomerInvoice> CustomerInvoices { get; set; }
= new List<CustomerInvoice>();
public class Products
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public string Company { get; set; }
public float Price { get; set; }
public int Quantity { get; set; }
public string Description { get; set; }
public string ProductImage { get; set; }
public string Code { get; set; }
public ICollection<CustomerInvoice> CustomerInvoices { get; set; }
= new List<CustomerInvoice>();
}
public class CustomerInvoice
{
public int CustomerInvoiceId { get; set; }
public int Quantity { get; set; }
public float Discount { get; set; }
public float TotalPrice { get; set; }
public int InvoiceId { get; set; }
public Invoice Invoice { get; set; }
public int ProductId { get; set; }
public Products Products { get; set; }
public ICollection<ProductsReturn> ProductsReturn { get; set; }
= new List<ProductsReturn>();
}