Users / \ / \ M-T-O M-T-O / \ / \ Products----M-T-M----Tags
I wonder if there is any documentation on how to create a schema like this with entities. I got stuck at wondering which entity should be responsible for what in the relation.
For example:
Lets say I want to add a tag to a product. I have a method like this in my
product entity:
public virtual void AddTag(Tag tag)
{
this.Tags.Add(tag); // IList<Tag> Tags
tag.AddProduct(this);
}
First this adds a the tag object to the list of Tags. Then that tag object adds 'this' product to it's own list of products.
So far so good.
But what if I want to add a product to a tag. I have a method like this in my
tag entity:
public virtual void AddProduct(Product product)
{
this.Products.Add(product); // IList<Product> Products
// product.AddTag(this);
}
So first I add the product object to a list of products in my tag object. I could then add 'this' tag to the Product but this is where I got stuck. The method that is commented throws a stackoverflow error because it calls back to AddProduct which calls AddTag and so on and so on.
Not sure if my schema is really correct either. The M-T-O from user to tags is there to make it easy when I want to see what tags a user has.
So I was wondering if anybody could point me into the right direction?
Thanks in advance,
Pickels