Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, July 5, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: Cascading delete conflict
Doug Evenhouse
Posts: 66
 
Cascading delete conflictYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Aug 09 12:42 AM
I have a custom entity AccountService that has a child relationship with the Account entity with a cascading delete. The AccountService entity has an OnBeforeDelete event with code that updates a field in Account, like this:

public static void OnBeforeDeleteStep( IAccountService accountservice, ISession session)
{
IAccount acc = accountservice.Account;
if (acc != null)
{
acc.UpdateLeadscore();
session.Save(acc);
}
}

The problem is that if I delete the Account entity, this AccountService entity OnBeforeDelete event will try to update the Account entity causing the following error:

An exception occurred executing the dynamic method AccountService.OnBeforeDelete.:
deleted object would be re-saved by cascade (remove deleted object from associations)

Does anyone know how I can detect in the event code above when the Account is in the process of being deleted? I guess I could write code to delete the associated AccountServices collection in the OnBeforeDelete event of the Account and turn off the cascading delete for the relationship. Or is there a better way to handle this?


Thanks!
Doug
[Reply][Quote]
Mike LaSpina
Posts: 116
 
Re: Cascading delete conflictYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Aug 09 11:36 AM
Doug - you always come up with the hard ones!

Try dissociating the account service at this point:
accontservice.Account.accountservices.Remove(accountservice);

This will prevent the cascading delete.

[Reply][Quote]
Doug Evenhouse
Posts: 66
 
Re: Cascading delete conflictYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Aug 09 1:29 PM
Thanks Mike - I'm not looking for trouble, honest!

I will try your suggestion. If it works I think it will be preferable to what I ended up doing.

I turned off cascading delete for the AccountService relationship with Account and added the following Post Execute Step to the OnBeforeDelete event on Account:


public static void OnBeforeDeleteStep( IAccount account, ISession session)
{
try
{
IDbCommand command = session.Connection.CreateCommand();
session.Transaction.Enlist(command);
string str = "DELETE FROM RSI_ACCOUNTSERVICE WHERE ACCOUNTID ='" + account.Id + "'";
command.CommandText = str;
command.ExecuteNonQuery();
}
catch (Exception exception)
{
session.Transaction.Rollback();
throw new Exception(string.Format("An error occurred while deleting services for the account.", account.AccountName, account.Id), exception.InnerException);
}
}


This seems to be working but feels wrong to circumvent the ORM this way. It's based on the code for the standard OnBeforeDelete event for Account which can be seen using .NET Reflector. Any idea why the supplied code for this event deletes some entities (mostly related to Activity) using this method and not others (such as Opportunity and Contact)? As far as I can tell associated Opportunities and Contacts (for example) are deleted by NHibernate as part of the cascade logic defined in the relationship.

-Doug
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/5/2025 3:01:05 AM