.Save function not updating record

Posts   
 
    
Posts: 18
Joined: 06-Dec-2012
# Posted on: 18-Jul-2013 14:52:31   

I walked through the code and everything is good until is executes the .Save function. Here is my code.

Public Function SaveCrewJob(ByVal job As CrewJob) As Boolean Implements INeslService.SaveCrewJob Dim jobEntity As CrewJobEntity = Nothing

    Try
        jobEntity = Translation.CrewJobContractToEntity(job)

        jobEntity.IsNew = IIf(jobEntity.FetchUsingPK(jobEntity.BusinessUnit), False, True)

        Return jobEntity.Save()

    Catch ex As Exception
        Throw New FaultException(ex.ToString)
        Return False
    End Try
    Return False
End Function

The line of code that has Translation in it deals with converting a datacontract in my web service to a entity object. Now the businessUnit value is a string. When trying to do an update to the record it does come back as a false response. So it can find the existing record in the database. Now I can say I'm using the exact same code for other entities and I'm not having this issue. It is only with this entity. Is there a way I can debug what is happening in the .Save function? Thank you for all the help.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jul-2013 20:30:58   

Please enable DQE tracing, grab the SQL Update Command produced, and run it manually against the database, and see if it really finds and updates a record or not.

Posts: 18
Joined: 06-Dec-2012
# Posted on: 18-Jul-2013 20:45:09   

I found out how to turn on the DQE trace. What I found out is that there is not an update statement being created. When I add a new record. There is a new insert statement created. Do you have an idea why there is no Update statement created? Could it be entity related?

Here is an insert statement.

Generated Sql query:

    Query: INSERT INTO "NESL"."CREW_JOB" ("ADDRESS", "BEGIN_DT", "BUSINESS_UNIT", "CITY", "COMMENTS", "ECMS_NO", "END_DT", "HOME_MCU", "NTAN8_LEAD", "STATE", "ZIP_CODE") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11)
    Parameter: :p1 : String. Length: 40. Precision: 0. Scale: 0. Direction: Input. Value: "dasd".
    Parameter: :p2 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 7/11/2013 12:00:00 AM.
    Parameter: :p3 : StringFixedLength. Length: 12. Precision: 0. Scale: 0. Direction: Input. Value: "    15001289".
    Parameter: :p4 : String. Length: 25. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: :p5 : String. Length: 2000. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: :p6 : String. Length: 20. Precision: 0. Scale: 0. Direction: Input. Value: "44444".
    Parameter: :p7 : Date. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 7/31/2013 12:00:00 AM.
    Parameter: :p8 : StringFixedLength. Length: 12. Precision: 0. Scale: 0. Direction: Input. Value: "    10033200".
    Parameter: :p9 : Decimal. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 0.
    Parameter: :p10 : StringFixedLength. Length: 2. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: :p11 : String. Length: 12. Precision: 0. Scale: 0. Direction: Input. Value: "".

But when I try to update this new record. I don't get an update statement for it.

Posts: 18
Joined: 06-Dec-2012
# Posted on: 18-Jul-2013 21:57:30   

I removed the statement to see if this is a new record or not and here is the message I got when trying to update a record.

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of an action query: ORA-00001: unique constraint (NESL.CREW_JOB_0) violated. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. ---> Oracle.DataAccess.Client.OracleException: ORA-00001: unique constraint (NESL.CREW_JOB_0) violated

So the constraints are working with the keys of the object. There is one more thing that I forgot to say. The DBA changed a name of one of the columns and increased it size. I did a refresh of the data model and recreated my project. Could this be the problem? Do I need to do something special.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Jul-2013 05:45:46   

The problem is this line:

jobEntity.IsNew = IIf(jobEntity.FetchUsingPK(jobEntity.BusinessUnit), False, True)

... when you do jobEntity.FetchUsingPK(...), you are actually refreshing the object from the values on DB. So, if the entity exists on DB, all the properties of jobEntity are reset to your DB values. As the properties are set again, all currentValues and dbValues are the same for that entity, thus the .Save action doesn't detect any changes (dbValues = currentValues) and no Update is emitted as there is nothing to save.

To overcome that, check the existence with another object, such as:

jobEntity = Translation.CrewJobContractToEntity(job)

' check the existing on DB
Dim jobCheck As JobEntity = New JobEntity()
jobEntity.IsNew = Not  jobCheck.FetchUsingPK(jobEntity.BusinessUnit)

Return jobEntity.Save()
David Elizondo | LLBLGen Support Team
Posts: 18
Joined: 06-Dec-2012
# Posted on: 19-Jul-2013 14:35:16   

That fixed my issue. Thank you.