Updating global fields

Posts   
 
    
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 22-Nov-2006 13:07:35   

I'm new to this and will try to read the documentation, but could someone point me in the right direction please?

We have a **ModifiedDate **field on every table. Ideally I would like to update this to Now() when Inserting or Amending.

Can I do this globally, or do I have to do it for all tables specifically, eg Employees.ModifiedDate?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Nov-2006 13:47:26   

What are you using: adapter or selfservicing?

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 22-Nov-2006 13:54:20   

We are using Adapter.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 22-Nov-2006 14:17:37   

Hi,

A solution if you don't want to modify each time the field is to use OnPropertyChanged() method. When a field is modified, in the OnpropertyChanged, you can modify the date field and so insert Date.Now().

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Nov-2006 14:51:25   

We have templates available (for customers, but I can mail them to you) which generate a common base class between the generated entities and the central base class EntityBase2. You could add to that generated class the override of that OnPropertyChanged method so it works for all entities.

You can also use a different route: Create a partial class of DataAccessAdapter in the dbspecific project and override OnBeforeEntitySave and set the field there. This then works for all entities as well.

In there do something like: entitySaved.SetNewFieldValue("ModifiedDate", DateTime.Now);

it then will be included in the query when the query is generated

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 22-Nov-2006 18:00:25   

Thanks. I'll get back when we've bought the product.

Sorry for the delay but I've been coding all day. I've written 5 lines of code and my form shows my table in a Janus grid.

I have RSI now. smile