Good day guys,
I've got quite a specific data model that I'm trying to create in POCO classes, and I've tried so many different approaches and visited so many websites, but none seem to cover my specific example.
So I'm going to throw this out there and hope someone can help me.
I've got products, and products have ingredients. In our business though, these products can get supplied by different vendors, each with a slightly different set of ingredients.
So I've got my base classes:
public class Product
{
public int ProductID { get; set; }
public string ProductNumber { get; set; }
public string Description { get; set; }
public virtual ICollection<Supplier> Suppliers { get; set; }
}
public class Vendor
{
public int VendorID { get; set; }
public string Name { get; set; }
public virtual ICollection<Supplier> Suppliers { get; set; }
}
public class Ingredient
{
public int IngredientID { get; set; }
public string Name { get; set; }
}
public class Supplier
{
public int SupplierID { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Vendor> Vendors { get; set; }
}
So as you can see, I've gotten as far as realising that my model needs a join entity, because my ingredients come from a specific vendor for a product, I need that join entity called supplier (I think).
This is where I am getting stuck... My product can be supplied by one or more vendors. Each vendor, per product, will have a list of ingredients for that product
I can't even get past whether I need the join entity or not.
What would be awesome was if I could navigate the data structure like this (or something similar):
articles[1].Vendors[3].Ingredients;
Yet again, I don't know enough about Entity Framework to know if this is possible.
The way I'm doing it now feels... wrong. What is the correct way to be doing what I want to do? Do I need the join table or can I somehow navigate the ingredients for a vendor for a product, maybe using the modelbuilder to make the product->vendor->ingredient link required?
Any help would be greatly appreciated!
Edit: I also think I don't understand enough about Entity Framework's relationship ideas.
So one product can have multiple vendors, which is a 1-to-many relationship. But a Vendor can have many products. So is this actually a many-to-many?
I can definitely model what I want to do on a SQL Express server, but I really want to use Entity Framework. I just need a better understanding of my modelling requirements.
Product,SupplierandIngredient. Is it correct?Productwill always have 1-to-manySuppliers(vendors) and aSupplierwill have 1-to-manyingredientsfor that product. I've also wondered whether I should rather carry an ingredient set and associate a set of ingredients with a supplier for a given product.