Hi, i had the same problem. You give me some ideas, try inverse=true
only in parent class. This way:

class A {
 [PrimaryKey("A_ID")]
 public int Id { get; set; }
 [HasMany(Inverse=true,
Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
 public IList<B> BList { get; set; }
}

that way work for me. But what inverse is for? without this the
framework try to update child class with A_ID=null but database
constraint restrict it, with inverse=true, delete childs first then
parent.


Gonzalo

On 10 feb, 11:44, Joao Carlos <[email protected]> wrote:
> Hello again,
>
> I´ve made some modifications and came up with the following:
>
> class A {
>  [PrimaryKey("A_ID")]
>  public int Id { get; set; }
>
>  [HasMany(Inverse=false,
> Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
>  public IList<B> BList { get; set; }
>
> }
>
> class B {
>  [PrimaryKey("B_ID")]
>  public int Id { get; set; }
>
>  [BelongsTo("A_ID")]
>  public A AId { get; set; }
>
> }
>
> when i call A.Delete() the A object is deleted and the B one appears
> updated with a null reference on A_ID field.
> since the constrains are still being generated I am assuming that all
> children are being updated with a null reference before the A object
> gets deleted, but unfortunately the B children are not deleted after
> that, they just remain as orphans.
>
> any ideas?
>
> On 9 fev, 16:32, Joao Carlos <[email protected]> wrote:
>
>
>
> > Hello,
>
> > I´ve been trying to use cascade delete, but, for some reason, it is
> > not working ;/
> > I checked most of the cascade delete topics but nothing seems to work
> > for me, so, any help is appreciated.
>
> > Here´s a prototype of what I have:
>
> > [code]
> > class A {
> > [PrimaryKey("A_ID")]
> > public int Id { get; set; }
>
> > [HasMany(Inverse=true,
> > Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
> > public IList<B> BList { get; set; }}
>
> > [/code]
>
> > [code]
> > class B {
> > [PrimaryKey("B_ID")]
> > public int Id { get; set; }
>
> > [BelongsTo("A_ID")]
> > public A AId { get; set; }
>
> > [HasMany(Inverse=true,
> > Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
> >         public IList<C> CList { get; set; }}
>
> > [/code]
>
> > [code]
> > class C {
> > [PrimaryKey("C_ID")]
> > public int Id { get; set; }
>
> > [BelongsTo("B_ID")]
> > public B BId { get; set; }}
>
> > [/code]
>
> > and this is the error I get:
> > [code]
> > [OracleException (0x80131938): ORA-02292: integrity constraint
> > (PROJECTNAME.FK929B9C00F122688D) violated - child record found
> > ]
> >    System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle
> > errorHandle, Int32 rc) +166
> >    System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle
> > statementHandle, CommandBehavior behavior, Boolean needRowid,
> > OciRowidDescriptor& rowidDescriptor, ArrayList&
> > resultParameterOrdinals) +1719
>
> > System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean
> > needRowid, OciRowidDescriptor& rowidDescriptor) +503
> >    System.Data.OracleClient.OracleCommand.ExecuteNonQuery() +140
> >    NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
> > +261
> >    NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation
> > expectation) +49
> >    NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object
> > id, Object version, Int32 j, Object obj, SqlCommandInfo sql,
> > ISessionImplementor session, Object[] loadedState) +1277
>
> > [GenericADOException: could not delete: [A#90][SQL: DELETE FROM A
> > WHERE A_ID = ?]]
> >    AA.Delete() in AA:152
> >    AA.Process() in AA.cs:105
> >    AList.GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs
> > e) in AList.aspx.cs:39
>
> > System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs
> > e) +133
> >    System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row,
> > Int32 rowIndex) +604
> >    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
> > causesValidation, String validationGroup) +1134
> >    System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
> > eventArgument) +199
>
> > System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.Rais 
> > ePostBackEvent(String
> > eventArgument) +7
> >    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
> > sourceControl, String eventArgument) +11
> >    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
> > +177
> >    System.Web.UI.Page.ProcessRequestMain(Boolean
> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> > +1746
> > [/code]
>
> > Can anyone help?

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en.

Reply via email to