How to update a field with dbfunction call using SaveEntityCollection

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 02-Oct-2012 13:39:32   

Hi,

I need to update one field using a db function call:

UPDATE some_table SET some_field= ... , last_modified=current_timestamp ,... WHERE ....

Using the SaveEntityCollection. How can I Apply that ?

Best Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Oct-2012 22:05:49   

You can SetExpression on the entityfield, which can accepts a DBFunctionCall object.

Something like:

employee.Fields[(int)EmployeeFieldIndex.Salary].SetExression( new DBFunctionCall("GetCurrentTimeStamp()", 
    new object[] {}"));

empCollection.Add(employee);
adapter.SaveEntityCollection(empCollection);
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 03-Oct-2012 09:58:57   

Great - it works simple_smile

Is it possible to call a function

current_timestamp

without brackets

current_timestamp()

using a standard LLBLGen methods or should I inherit from DbFunctionCall?

I'm using postgresql. The function without brackets has a default precision which is required by my client.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 03-Oct-2012 10:58:55   

You can subclass dbfunction call and override ToQueryText, you can also use a trick:

employee.Fields[(int)EmployeeFieldIndex.Salary].SetExression( new DBFunctionCall("current_timestamp{0}",
    new object[] {string.Empty}"));

this will trick the dbfunctioncall the function is pre-formatted, so it won't append () itself, but there's no preformatting going on, you append an empty string wink

Frans Bouma | Lead developer LLBLGen Pro