Print Page | Close Window

[Solved] Deletion Guard

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=425
Printed Date: 11-Jun-2026 at 10:37pm


Topic: [Solved] Deletion Guard
Posted By: Linguinut
Subject: [Solved] Deletion Guard
Date Posted: 12-Sep-2007 at 2:01pm
I mimicked the deletion guard code in one of my business objects:
 
/// <summary>Get if allowed to delete this customer.</summary>
/// <remarks>Don't permit delete of customer with orders.</remarks>[Bindable(false)]
[
BindingBrowsable(false)]
public override bool AllowDelete
{
   
get
   
{
       
if (SalesOrderMasters.Count > 0)
        {
// has orders...do not delete
           
return false;
        }
return true;
    }
}
 
Please note that the override throws an exception stating that there is nothing to override (in my CustomerMaster object?).  If I remove the override, then it builds and the app runs.  I did the same on another object.  Here is the message I get when I click the delete button from the navigator:
 
"Are you sure that you want to delete 'MyCompany.MyNamespace.Model.MyObject'?"
 
Whoa!  Scary!  Not quite what I want to do.  I will dig into the code a bit more to find out what is going on, but a quick response here from "someone in the know" would move things along.
 
So, two questions: 
1)  Do I need the override in the deletion guard code?
2)  How are the strings handled in the actual delete code?
 
Thanks,
Bill
 



Replies:
Posted By: Linguinut
Date Posted: 12-Sep-2007 at 2:34pm
I added this:
 
/// <summary>Get the displayable name of this object instance (e.g., "Nancy Davolio").</summary>
/// <remarks>Typically useful in validation messages.</remarks>
[BindingBrowsable(false)]
public override string EntityInstanceName { get { return CustName; } }
 
It didn't help.  I got the same kind of build error...no suitable method found to override (EntityInstanceName).  I must not have the proper reference setup somewhere.


Posted By: Bill Jensen
Date Posted: 12-Sep-2007 at 4:53pm
Are you sure your entity class is inheriting (directly or indirectly) from IdeaBlade.Common.EntityModel.CommonEntity?
 
Bill J.


Posted By: Linguinut
Date Posted: 12-Sep-2007 at 6:29pm
Nope.  Haven't checked.  However, this leads me to another post that I made:  http://www.ideablade.com/forum/forum_posts.asp?TID=369 - http://www.ideablade.com/forum/forum_posts.asp?TID=369 .  In it I asked if the object mapper would account for the CAB structure.  It obviously does not.  But, will it?  One day?
 
I will see about altering the inheritance, then trying again.  Thanks for the response!
 
Bill


Posted By: Linguinut
Date Posted: 12-Sep-2007 at 6:46pm
Ahhhhhh...this is not good.  My objects, created by the object mapper tool, skip the BaseEntity and the CommonEntity and inherit directly from Entity.  I had to manually add the inheritance to the BaseEntity to the "public abstract partial class" for the datarow.  That item was buried a bit.
 
Should I even be playing around in the datarow class file since it could be overwritten with the next update to the model project?
 
In the words of Barbarino:  I am so confused.  Confused


Posted By: Bill Jensen
Date Posted: 12-Sep-2007 at 6:59pm
Let the object mapper add the inheritance from BaseEntity.  That way it will remember and not overwrite it when you regenerate the model.
 
Then just be sure BaseEntity inherits from CommonEntity.
 
BaseEntity gives you a place to add your common entity behavior.
 
See my response to your earlier post as well at http://www.ideablade.com/forum/forum_posts.asp?TID=369 - http://www.ideablade.com/forum/forum_posts.asp?TID=369 . 
 
Sorry not to respond sooner.
 
Bill J.


Posted By: Linguinut
Date Posted: 12-Sep-2007 at 7:05pm

I did read your response on the other post.  Many thanks!!  I am in the object mapper right now, setting the base classes for my objects.  The BaseEntity thing certainly is the way to go...obviously!

Regenerating the objects, now.
 


Posted By: Linguinut
Date Posted: 12-Sep-2007 at 7:11pm
Great!  Deletion guard works beautifully.  Powerful stuff!



Print Page | Close Window