If have to set "who is the _right_ side of the relationship".
See inverse="true|false".

On Thu, Feb 12, 2009 at 10:27 AM, Jerrie Pelser <[email protected]>wrote:

>
> Hi,
>
> I have a table called ActivityCategory which has a hierarchical
> relationship.  The table is as follows:
>
> CREATE TABLE ActivityCategory(
>        Id int NOT NULL IDENTITY PRIMARY KEY,
>        Description nvarchar(250) NOT NULL,
>        ParentId int NULL
> )
>
> I have a mapping file as follows:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> assembly="DataModel"
>    namespace="DataModel">
>
>        <class name="ActivityCategory" table="ActivityCategory">
>                <id name="Id" column="Id" type="int" unsaved-value="0">
>                        <generator class="identity"/>
>                </id>
>                <property name="Description" />
>
>                <many-to-one name="Parent" class="ActivityCategory"
> column="ParentId" />
>
>                <set name="Categories" table="ActivityCategory"
> cascade="all">
>                        <key column="ParentId" />
>                        <one-to-many class="ActivityCategory" />
>                </set>
>        </class>
> </hibernate-mapping>
>
> and my class definition is:
>
>    public class ActivityCategory
>    {
>        public virtual ISet<ActivityCategory> Categories { get; set; }
>        public virtual string Description { get; set; }
>        public virtual int Id { get; set; }
>        public virtual ActivityCategory Parent { get; set; }
>    }
>
> When I add a child category to the Categories collection of the
> parent, and save the parent then the child category does not save:
>
>                ActivityCategory category =
> session.Get<ActivityCategory>(1);
>                ActivityCategory childCategory = new ActivityCategory
> { Description = "New Test Category" };
>                category.Categories.Add(childCategory);
>
>                session.SaveOrUpdate(category);
>
> If I change it around and do the following the child category does
> save:
>
>                ActivityCategory category =
> session.Get<ActivityCategory>(1);
>                ActivityCategory childCategory = new ActivityCategory
> { Description = "New Test Category" };
>                childCategory.Parent = category;
>
>                session.SaveOrUpdate(childCategory);
>
> How do I get the first scenario to work (saving the child categories
> when saving the parent category)?
>
> I am using a SQL Compact database and using the SQL Ce dialect and
> driver.
>
> Regards
> Jerrie Pelser
>
> >
>
>


-- 
Dario Quintana
http://darioquintana.com.ar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to