Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Database drivers> Capture Delete to change status rather then remove record
 

Pages: 1
Database drivers
Capture Delete to change status rather then remove record
Page:1/1 

  Print all messages in this thread  
Poster Message
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
73 posts
# Posted on: 21-Apr-2009 13:50:43.  
I'd like to write some code (adding to the CustomEntityBase class?) so that when I call the Delete on any of my entities the StatusID field of the entity is set rather than the Entity being deleted. Is this possible?

I've tried things like in the CustomEntityBase class:

Code:

Private _RealDelete As Boolean

Public Property RealDelete() As Boolean
     Get
        Return _RealDelete
     End Get
     Set(ByVal value As Boolean)
        _RealDelete = value
     End Set
    End Property

Protected Overrides Sub OnDelete()
     If _RealDelete Then
        MyBase.OnDelete()
     Else
        Me.Fields("StatusId").CurrentValue = StatusEntity.Deleted
        Me.Save()
     End If
    End Sub



Code:
Public Overloads Function Delete() As Boolean
     If _RealDelete Then
        MyBase.OnDelete()
     Else
        Me.Fields("StatusId").CurrentValue = StatusEntity.Deleted
        MyBase.Save()
     End If
    End Function


Any suggestions gratefully received!

Winforms Vb.net in Visual Studio 2008 Sp1, llblgen 2.6, access mdb
  Top
Seth
User



Location:
Los Angeles, CA
Joined on:
25-Mar-2006 02:56:26
Posted:
204 posts
# Posted on: 21-Apr-2009 20:09:18.  
Here is what Frans has to say about that kind of thing. That being said, you should be able to change it using Auditors and dependency injection.

______________________________
Seth Juarez
http://www.sethjuarez.com
 
Top
MTrinder
User



Location:
London by day, Milton Keynes by night.
Joined on:
08-Oct-2008 17:55:47
Posted:
1461 posts
# Posted on: 21-Apr-2009 21:32:30.  
It depends if you are using self-servicing or adapter. If SS you will need to modify the template so that it sets the flag for you rather than deleting the entity.

If adapter, you can inherit from DataAccessAdapter and override the delete methods to set the flag for you rather than deleting the entities.

It's generally a crappy solution for performace though as every query then needs to filter out "deleted" entities - and because the selectvity on the "deleted" column won't be very high (all of your "undelted" records are null - i'm guessing this will be the majority of them) indexing it doesn't gain you a great deal - you will end up with a lot of table scans.
  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
73 posts
# Posted on: 22-Apr-2009 09:49:03.  
Wow.. just read Frans's post re soft deletes. My situation is different again (I think) I have a "mission-critical" application running at a number of remote sites) which all need to be periodically synchronised with each other and a master database. (Local copies of the database are held so the the application can continue to be used if the communications link back the the master database is broken) Any of the remote sites may choose to delete a record (albeit on very rare occaisions). The only way I can think of doing this is to flag a record as deleted so that when the remote and master databases are compared I can flag records as deleted in the master which will then ripple out the the other remote sites as they sync. If I just remove a record from the local then the sync with the master will just bring the record back.

What I wanted to do was to be able to call Entity.Delete to "soft-delete" the record, but if I set Entity.TrueDelete=True then call Entity.Delete the record would be removed from the database.

I guess what I can do is create an Entity.FlagAsDeleted in CommonBaseEntity as a equally "elegant" solution.

Code:
Public Function FlagAsDeleted() As Boolean
     Me.Fields("StatusId").CurrentValue = StatusEntity.Deleted
     Return Me.Save()
    End Function


Thanks for your comments.


  Top
Seth
User



Location:
Los Angeles, CA
Joined on:
25-Mar-2006 02:56:26
Posted:
204 posts
# Posted on: 22-Apr-2009 19:50:35.  
I honestly think Auditors is the way to go....
______________________________
Seth Juarez
http://www.sethjuarez.com
 
Top
rdhatch
User



Location:
Green Bay, WI
Joined on:
03-Nov-2007 18:01:49
Posted:
198 posts
# Posted on: 22-Apr-2009 20:08:21.  
Hi Like -

What database are you using? Are you planning on manually synching these databases? I've been there before. Not worth it.

Would not SQL Replication take care of all this for you?

Ryan


Ryan D. Hatch  Top
MTrinder
User



Location:
London by day, Milton Keynes by night.
Joined on:
08-Oct-2008 17:55:47
Posted:
1461 posts
# Posted on: 23-Apr-2009 21:13:02.  
I'm with Ryan - manually keeping DB's in sync is a colossal PITA. Just think of all the work that has gone into making SQL replication work - why re-invent the wheel...!

Matt
  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
73 posts
# Posted on: 27-Apr-2009 11:50:56.  
I have a working solution now.

I am syncing a number of remotely located Microsoft Access 97 databases with a central Oracle one. I don't want the "overhead" of having to support local installations of Oracle/SQL Server/MSDE at the remote sites: with Access 97 databases I can copy an "empty"installation of the application to a pc at the remote location, then press the replicate button to get a new pc up and running within minutes. I am able to work on the principal of 'who updated it last gets to win' on a record by record basis and there will only be deletes(flagged or otherwise) on a very rare occasions so things are pretty simple.

Thanks for everyone for your comments.


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.