Problem With DBFunctionCall

Posts   
 
    
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 13-Dec-2007 20:24:58   

Hi,

What is the problem with these DBFunctionCalls?

Dim exp As IExpression = New DbFunctionCall("getdate", Nothing)
Employee.Fields(EmployeeFields.LastUpdatedDate.FieldIndex).ExpressionToApply = exp

Dim exp2 As New Expression(EmployeeFields.NAME)
Employee.Fields(EmployeeFields.Code.FieldIndex).ExpressionToApply = exp2

Employee.Save

The first one update the field LastUpdatedDate with the server date The second one update the field Code with the contents of field Name (just for test)

When save the employee entity, the two fields(LastUpdatedDate,Code) are always saved null in db

Where is my mistake?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Dec-2007 09:42:43   

Please try to set the IsChanged of each field to true.

Also you can use the example in the docs in the Expressions in entity updates section found here: "Using the generated code -> Field expressions and aggregates"

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 14-Dec-2007 11:18:22   

Is Employee new or an existing entity?

Frans Bouma | Lead developer LLBLGen Pro
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 15-Dec-2007 20:46:22   

Thanks Walaa, Otis

Employee object may be new or existing.

What I want to do is to save the CreationDate and LastUpdatedDate for Employee.

Walla suggestion works fine for update (set IsChanged to true), but doesn’t work for insert so I use GetDate() in database for insertion.

Is there any way to do it ByCode for insertion?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Dec-2007 19:57:32   

No, for insertion is not possible. However you could grab the values at code (that's more clean and clearly). In v2.5 Auditing was added, you can use such feature to grab log information in at a separate Auditor class.

David Elizondo | LLBLGen Support Team
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 16-Dec-2007 20:43:26   

Thanks, I will take a look at auditing mechanism soon as it is one of the requirement of the next project simple_smile