Remove Methods on Editable Root Collection not getting fired

Remove Methods on Editable Root Collection not getting fired

Old forum URL: forums.lhotka.net/forums/t/12618.aspx


AbbasMalik posted on Saturday, May 10, 2014

Hi

I have generated an Editable Root Collection through cslagenfork. In windows forms, binding source's Remove() or RemoveCurrent() method

is called to delete the current object. But some how the remove methods of the root collection (BusinessBindingListBase) are not getting fired. I have put some logic in the remove methods to check referential integrity.

        public new bool Remove(ColorEC item)        { 

            if (!CanDeleteObject())

                throw new System.Security.SecurityException("User not authorized to remove a ColorEC.");

            ColorRIExistsCommand cmd = new ColorRIExistsCommand(item.NKey);

            cmd = Csla.DataPortal.Execute<ColorRIExistsCommand>(cmd);

            if (cmd.ColorExists)

                throw new System.Exception("Related records exist. Can't delete record");

            return base.Remove(item);

        } 

 

Edit:

When I delete a record using binding source, RemoveItem(int index) gets called.Overriding this method and putting RI logic into it works. Is it right way to do it something else needs to be done?

ajj3085 replied on Sunday, May 11, 2014

I think your problem is your use of shadowing via the new keyword.  Your method would only be called if the caller is using a reference to your class.  if the reference is to the base of your class the normal Remove method is called.  This is why use of new is discouraged, because it breaks inheritance.

 

http://joel.inpointform.net/software-development/polymorphism-in-c-new-vs-override-as-function-modifiers/

AbbasMalik replied on Wednesday, May 14, 2014

Hi Andy, 

new keyword is not used anywhere. Overriding RemoveItem in the derived collection class works good with the windows forms binding source.

Best regards

Abbas

ajj3085 replied on Wednesday, May 14, 2014

This is from your OP:   public new bool Remove(ColorEC item) at the start of the thread.

Is that not what your code actually looks like?  If not, can you post the actual code?

AbbasMalik replied on Thursday, May 15, 2014

Thanks Andy, you pointed me out to the right direction and now I have understood it. Right now I have overridden RemoveItem(ColorEC item) and it is working fine. Is it ok to override only this method or should I override all the base class remove methods to enforce the referential integrity logic?

Thanks again.

ajj3085 replied on Thursday, May 15, 2014

I believe that the other remove methods end up calling the overridden one, but id check the code to be sure.

Copyright (c) Marimer LLC