Save entity

Posts   
 
    
Posts: 54
Joined: 22-Jun-2010
# Posted on: 30-Jul-2010 16:21:45   

Hi

I just moved my declarations as follows

#region Fields

    private static readonly DataAccessAdapter adapteraccountnature = new DataAccessAdapter();
    private static readonly IPredicateExpression filteraccountnature = new PredicateExpression();

    private static AccountnatureEntity accountnature = new AccountnatureEntity();

    #endregion Fields

Then I wrote the save function

adapteraccountnature.FetchEntity(accountnature); accountnature.Description = ChangeCase.ToTitleCase(tbxdescription.Text.Trim()); accountnature.Createddate = ServerDateTime.getcurrentserverdatewithtime(); accountnature.CreateduserId = StandardMessage.loginuserid;

            var succeeded = adapteraccountnature.SaveEntity(accountnature);

            if (succeeded)
            {
                message = StandardMessage.datasavesuccess;
                adapteraccountnature.CloseConnection();
                DoRefresh();
            }
            else
            {
                message = StandardMessage.datasavefailure;
                adapteraccountnature.CloseConnection();

            }

Now when I try to save i get error, outofsync !

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jul-2010 04:44:07   

What does DoRefresh()? The thing is that if DoRefresh() uses the saved entity to read some properties, the entity should be refetched. To understand this, I quote the manual:

...The entity object itself is marked 'out of sync'. This means that the entity’s data has to be refetched from the database prior to reading from one of the entities properties. SelfServicing will handle this automatically but with Adapter you must refetch manually using an adapter object. If you specify 'true' in the SaveEntity call, this automatically refetches the entity for us. If you do not require the saved entity for any further processing, you don't need to refetch it and you can save yourself a roundtrip by simply omitting the 'true' in the SaveEntity() call.

David Elizondo | LLBLGen Support Team
Posts: 54
Joined: 22-Jun-2010
# Posted on: 31-Jul-2010 06:22:48   

daelmo wrote:

What does DoRefresh()? The thing is that if DoRefresh() uses the saved entity to read some properties, the entity should be refetched. To understand this, I quote the manual:

...The entity object itself is marked 'out of sync'. This means that the entity’s data has to be refetched from the database prior to reading from one of the entities properties. SelfServicing will handle this automatically but with Adapter you must refetch manually using an adapter object. If you specify 'true' in the SaveEntity call, this automatically refetches the entity for us. If you do not require the saved entity for any further processing, you don't need to refetch it and you can save yourself a roundtrip by simply omitting the 'true' in the SaveEntity() call.

I got it. I was trying for inmemory where it does not work. I just had to reinitialize the entity during save