Let's say in our project we use C# and MsSQL and we have one Products table with two columns (ID,Name)
One day we decided to save product information given by Company1, so we created a new table ProductInfoFromCompany1 because it has custom columns (ProductID, Price, CurrentScore)
The next day, we agreed with Company2 and now we need to save their data as well. So, new table -> ProductInfoFromCompany2 with different columns (ProductID, Year, Rating)
Another day, we agreed with Company3 and so on...
So, we have no idea how the data given by new companies will look like. That's why we need to create a new table because if we use one Details table, it will be too wide with numerous null columns
In Entity Framework Core we have these models:
public class ProductInfoFromCompany1 { public int Id { get; set; } public int ProductId { get; set; } public decimal Price { get; set; } public double CurrentScore { get; set; } public Product Product { get; set; } } public class ProductInfoFromCompany2 { public int Id { get; set; } public int ProductId { get; set; } public int Year { get; set; } public double Rating { get; set; } public Product Product { get; set; } } public class Product { public int Id { get; set; } public string Name { get; set; } //Do we need these navigation properties in this class? //public ProductInfoFromCompany1 ProductInfoFromCompany1 { get; set; } //public ProductInfoFromCompany2 ProductInfoFromCompany2 { get; set; } } You can see my question is commented in the Product class.
Do we need to add navigation properties in the Product class?
The reason why I'm asking is that in all books or documentation which I've read, people use navigation property, but in this case, it violates open-closed principle because whenever we add new company, we need to modify Product class as well.
P.S. if we want to query ProductInfoFromCompany1 data and we have product Id, we can simply start querying from ProductInfoFromCompany1, like this
var info = _db.ProductInfoesFromCompany1.Where(c=>c.ProductId == productId);
Productentity have two different types of product information? Or does it have a list of the same kind of product information produced by different companies? It looks like the classes are misnamed andProductshould have aRatingand aPricingproperty. Whether those classes needProductandProductIDis another matter. Most likely they do