Why isn't this entity saved?

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 18-Oct-2010 19:04:19   

Hi there,

I have...

            orderDetailEntity.AccountAssignment[0].Account = newAccount;

            adapter.SaveEntity(orderDetailEntity.AccountAssignment[0], true, true);

LLBLGen is saving 'newAccount' but 'AccountAssignment[0]' is still referencing the old and its IsDirty status is false.

Shouldn't it be updated?

Cheers, Ian.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Oct-2010 04:18:20   

Is orderDetailEntity.AccountAssignment an m:n relation?

David Elizondo | LLBLGen Support Team
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 19-Oct-2010 17:00:54   

Its 1:n.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-Oct-2010 20:50:37   

Does SQL profiler show the correct entities being saved, and then reloaded ?

Matt

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 20-Oct-2010 01:00:06   

If I remember correctly, it was showing the account being saved and re-fetched but the account assignment was not updated.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Oct-2010 05:33:53   

We will try to reproduce it. What is your Runtime Library version?

David Elizondo | LLBLGen Support Team
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 20-Oct-2010 10:01:28   

It was 2.6.10.421.

To get it to work I've been using...

            adapter.SaveEntity(newAccount, true, true);

            accountAssignmentEntity.AccountId = newAccount.AccountId;
            accountAssignmentEntity.Account = newAccount;

            adapter.SaveEntity(accountAssignmentEntity, true, true);
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Oct-2010 11:09:59   

Could you please post the complete code (which doesn't work)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 20-Oct-2010 11:39:02   

Looks like an fk field isn't synced directly? This is logical, as newAccount is likely an entity with an identity PK, so it's synced after the save of newAccount. This makes orderDetailEntity.AccountAssignment[0] not dirty at assignment, but it IS saved. orderDetailEntity.AccountAssignment[0] isn't reset to a new entity, the Fk field is just updated.

Could you please confirm what exactly you expect and what actually happens?

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 20-Oct-2010 20:11:59   

I was expecting the original code to insert the new account and for the account assignment to be updated to reference the new chalet such that...

accountAssignmentEntity.AccountId

...has the value of the new account's pk (which is indeed an identity column) and...

accountAssignmentEntity.Account

...references the new account.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Oct-2010 10:16:53   

Walaa wrote:

Could you please post the complete code (which doesn't work)?

Please.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 21-Oct-2010 17:21:13   

It was literally just creating a new account and assigning it to a pre-existing account assignment. The only thing missing from the code in my first post is the newing up of the account.

One complication is that the account assignment references an AccountEntity where as the type of account created is a ChaletAccountEntity which inherits from AccountEntity.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Oct-2010 21:47:40   

Hi

Please can you give us the full details of the relationship of the entities and a full example of the code which does not work - it's a bit difficult to try and work out what's going on when the information only arrives in chunks...!

Thanks

Matt