OutOfSync - but why?

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Nov-2008 01:05:56   

Hi, I'm using Adapter 2.5 & VB in a test system and all of the code shown below is in the BL.

I've fetched some data using this code :

           Dim fundPlannedQtr As FundPlannedEntity
         fundPlannedQtr = CType(GetFundPlannedQtr(ProjectCode, FinYear, FinQtr), FundPlannedEntity)

.. but when I try to use a field in the retrieved entity (e.g. If fundPlannedQtr.CFAmount > 0) I get:

"The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance."

As I haven't saved it and am just fetching it, I can't see what the problem is (been staring at it too long).

Anyone see where I've gone wrong?

BTW: The Function GetFundPlannedQtr looks like this:

    Function GetFundPlannedQtr(ByVal ProjectCode As String, ByVal FinYear As Integer, ByVal FinQtr As Integer) As EntityBase2
        Dim filter As IRelationPredicateBucket = New RelationPredicateBucket()
        Dim adapter As New DataAccessAdapter
        Try
            Dim fundPlanned As New FundPlannedEntity
            filter.PredicateExpression.Add(FundPlannedFields.ProjectCode = ProjectCode)
            filter.PredicateExpression.Add(FundPlannedFields.FinancialYear = FinYear)
            filter.PredicateExpression.Add(FundPlannedFields.FinancialQtr = FinQtr)
            adapter.FetchEntity(fundPlanned)
            Return fundPlanned
        Finally
            adapter.Dispose()
        End Try
    End Function

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Nov-2008 03:57:25   

Hi Markiemak,

The default state for the entity.Fields is "OutOfSync", then if the entity if successfully fetched it's marked as "Fetched". But your entity isn't fetched because you didn't specify the primary key for it. You don't even use the filter.

To avoid this, please make sure _fundPlanned _is instantiated with the proper primary key.

David Elizondo | LLBLGen Support Team
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Nov-2008 15:29:15   

Thanks daelmo - Very silly of me, very late at night.