I'm using Entity Framework Core with PostGreSQL in an ASP.NET Core Web API. I'm having difficulty defining a set of entities where both Class A and Class B contain a collection of Class C.
The resulting tables / columns that get generated during a DB migration are not what I'd expect.
Consider the following table definitions:
public class Supplier
{
[Key]
public Guid SupplierId { get; set; }
public string SupplierName { get; set; }
public List<Commodity> Commodities { get; set; }
}
public class Consumer
{
[Key]
public Guid ConsumerId { get; set; }
public string ConsumerName { get; set; }
public List<Commodity> Commodities { get; set; }
}
public class Commodity
{
[Key]
public Guid CommodityId { get; set; }
public string CommodityName { get; set; }
}
These classes result in the following tables / columns being generated:
Suppliers
SupplierId
SupplierName
Consumers
ConsumerId
ConsumerName
Commodities
CommodityId
CommodityName
ConsumerId
How do I create the model class definitions so that the generated tables/columns preserve these relationships? Is there a way to enforce join tables getting created?
Is there a specific set of class/field annotations that I should be using?