Yauhen,

Your are basically trying really hard to do things in a wrong way.
Having a proper bidirectional relationship is the best way to maintain
cascading collections.
"Cyclic references" are not a problem, unless you are trying to
automatically serialize your domain entities (wrong).
If you absolutely don't want the Person reference and are willing to accept
two SQL statements (insert and update), plus having PersonAddress.PersonId
nullable in the DB, you can remove the property from PersonAddress
completely.

   Diego


On Tue, Apr 27, 2010 at 11:03, Yauhen <[email protected]> wrote:

> Hello All,
>
> I have problems with cascading of children.
>
> I want to map one to many objects Person
> and PersonAddress
>
>    public class Person
>   {
>           public virtual int Id {get; set;}
>           public virtual string FirstName {get; set;}
>        public virtual ICollection<PersonAddress> PersonAddress { get; set;
> }
>   }
>
>    public class PersonAddress
>    {
>          public virtual int Id {get; set;}
>          public virtual int PersonId {get; set;}
>        ...
>   }
>
> I don't want to have person object property in address. It creates
> cyclic references and don't necessary for my application.
>
>
> mapping file is like following:
>
>        <class name="Person"  table="Persons" >
>                <id name="Id" type="Int32" column="PersonId">
>                        <generator class="identity"/>
>                </id>
>                <set name="PersonAddress" table="PersonAddress" lazy="true"
> fetch="join" outer-join="true" cascade="all-delete-orphan">
>                        <key column="PersonId"></key>
>                        <one-to-many class="PersonAddress"/>
>                </set>
>
>        </class>
>
>        <class name="PersonAddress"  table="PersonAddress" >
>                <id name="Id" type="Int32" column="Id">
>                        <generator class="identity"/>
>                </id>
>                <property name="PersonId" column="PersonId" type="Int32"/>
>                <property name="PhoneWork" column="PhoneWork"
> type="String"/>
>
>        </class>
>
> when trying to insert Person with person address I am receiving
> exception. Because it tries to insert PersonAddress with invalid id
> (default -1, 0, etc).
>
> in samples that I have found it is specified back reference from child
> to parent
> <many-to-one. In my case I have't parent object and don't want it.
> Integer field could not be mapped.
> So is there way to do cascade insert without parent object?
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
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