I have got into a very weird issue: when importing a product, I try to delete all current categories and populate them again. The problem is that when I call .Delete() on a CategoryProductRelation object it is deleting categories for other products as well. Then after some debugging, I found this in reflector:
and when I look what KeyValue() returns:
So when I delete a CategoryProductRelation object it seems that it's deleting all relations to that category. However, this works if done from backend.
Any ideea if I am doing something wrong, or how should I delete category relations for a product?
You're absolutely correct. Subsonic doesn't handle composite keys very well - that is to say not at all. That's why we're moving to NHibernate for all data access. The relationship between products and categories is one of the very few places where we've got that construct.
CategoryProductRelation possible bug
Hi Søren,
I have got into a very weird issue: when importing a product, I try to delete all current categories and populate them again. The problem is that when I call .Delete() on a CategoryProductRelation object it is deleting categories for other products as well. Then after some debugging, I found this in reflector:
and when I look what KeyValue() returns:
So when I delete a CategoryProductRelation object it seems that it's deleting all relations to that category. However, this works if done from backend.
Any ideea if I am doing something wrong, or how should I delete category relations for a product?
Ok, I think I found a way, Iinstead of calling Delete() method on CategoryProductRelation instance, I use this:
CategoryProductRelation.Delete(x => x.ProductId == cpr.ProductId && x.CategoryId == cpr.CategoryId);
It seems to do the job.
Hi Andrei,
You're absolutely correct. Subsonic doesn't handle composite keys very well - that is to say not at all. That's why we're moving to NHibernate for all data access. The relationship between products and categories is one of the very few places where we've got that construct.
is working on a reply...