I have this mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="GS.Catalog.Item,GS.Catalog" table="gsc_Item" lazy="true">
<id name="Id" column="id" type="String">
<generator class="assigned"/>
</id>
....
<set name="Categories" table="gsc_Categorization">
<key column="itemId"/>
<many-to-many column="categoryId" class="GS.Catalog.Category, GS.Catalog"/>
</set>
</class>
</hibernate-mapping>
So, if I do item.Categories.Clear() it will not delete categories for this item.
Code:
public override void DeleteItemCategories(string id)
{
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();
Item item = (Item)session.Get(typeof(Item), id);
item.Categories.Clear();
session.Update(item);
tx.Commit();
NHibernateHelper.CloseSession();
}
What is solution?