try this instead
var line = audit.ClaimLineErrors[0];
line.Audit = null;
audit.ClaimLineErrors.Remove(line);

On Dec 15, 1:28 pm, welzie <[email protected]> wrote:
> I have an Audit object that contains a IList<ClaimError> named
> "ClaimLineErrors".  The "ClaimLineErrors" are inserting correctly when
> the Audit object is saved.  However when I remove a ClaimLineError
> from the  "ClaimLineErrors" IList and update the Audit, the associated
> ClaimLineError record is NOT deleted from the db even thought it is
> was removed from the audit's IList<ClaimError> before saving.  What am
> I doing wrong?
>
> //CODE EXAMPLE
> //retrieve an already saved audit, audit is NOT connected to a session
> when returned
> Audit audit = AuditDataRepistory.FindAudit(99);
> //remove the 1st element in the list (for example assume list contains
> at least one object)
> audit.ClaimLineErrors.RemoveAt(0);
> //open a new session and persist audit
> AuditDataRepistory.save(audit);
>
> //MAPPINGS
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> assembly="Entity" namespace="ClaimAudit.Entity">
>   <class name="ClaimAudit.Entity.Audit" lazy="false" table="audits">
>     <id name="Id">
>       <generator class="native"/>
>     </id>
>     <property name="Active" type="Boolean"/>
>     <property name="DateReceived"/>
>     <property name="DateAudited"/>
>     <bag name="ClaimLineErrors" lazy="false" cascade="all-delete-
> orphan">
>         <key column="AuditId" not-null="true" update="true"/>
>         <one-to-many class="ClaimLineError"/>
>     </bag>
>   </class>
> </hibernate-mapping>
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> assembly="Entity" namespace="ClaimAudit.Entity">
>     <class name="ClaimAudit.Entity.ClaimLineError" lazy="false"
> table="claimlineerrors">
>         <id name="Id">
>             <generator class="native"/>
>         </id>
>         <many-to-one name="Audit" class="Audit" column="AuditId" not-
> null="true" lazy="false"></many-to-one>
>     </class>
> </hibernate-mapping>

--

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