I have Entity structure like below
public abstract class Entity
{
public int Id { get; set; }
}
public class User : Entity
{
public ICollection<Product> Products { get; set; }
}
public class Warehouse : Entity
{
public ICollection<Product> Products { get; set; }
}
public class Product : Entity
{
public Warehouse Warehouse { get; set; }
public User User { get; set; }
}
As you can see User can has products and Warehouse also can have products. So Entity framework put 2 foreign keys over Product table that can be nullable.
We could also achieve similiar structure by bit of different entity modelling like below
public class User : Entity
{
public ICollection<UserProduct> Products { get; set; }
}
public class Warehouse : Entity
{
public ICollection<WarehouseProduct> Products { get; set; }
}
public class Product : Entity
{
}
public class WarehouseProduct : Entity
{
public Product Product { get; set; }
public Warehouse Warehouse { get; set; }
}
public class UserProduct : Entity
{
public Product Product { get; set; }
public User user { get; set; }
}
First Design look simpler without introduce new entitties but not sure that it is better or not.
I am trying to find which is best or which circumtances makes one of it better than other.