SaveEntityCollection Counts

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 07-Feb-2006 22:43:19   

1) EntityCollection.DirtyEntities.Count seems to return the 1st level count of dirty entities, not the total count of dirty entities in the collection graph.

2) EntityCollection.SaveEntityCollection(x,false,true); returns the total count of entities saved.

A) So except in simple cases on a succesfull save these won't be equal, right?

B) The save of the collection is done in a transaction. If the transaction fails/ rollsback will I be notified by the entitiesSavedCount being 0 or by an exception being thrown?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Feb-2006 07:42:56   

1) EntityCollection.DirtyEntities.Count seems to return the 1st level count of dirty entities, not the total count of dirty entities in the collection graph.

Yes

2) EntityCollection.SaveEntityCollection(x,false,true); returns the total count of entities saved.

Yes

A) So except in simple cases on a succesfull save these won't be equal, right?

Yes

B) The save of the collection is done in a transaction. If the transaction fails/ rollsback will I be notified by the entitiesSavedCount being 0 or by an exception being thrown?

If an exception occur, the Transaction will be rolled back and the exception will be thrown. Else if nothing was saved in the database without an exception occuring , the result will only be 0.

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 08-Feb-2006 13:10:56   

If an exception occur, the Transaction will be rolled back and the exception will be thrown.

So if a database constraint is violated, for example, an exception will be thrown?

Is there a way to identify which item in the collection caused the problem?

Else if nothing was saved in the database without an exception occuring , the result will only be 0.

Can this happen if there are dirty items and no exception is thrown?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 08-Feb-2006 14:05:22   

arschr wrote:

If an exception occur, the Transaction will be rolled back and the exception will be thrown.

So if a database constraint is violated, for example, an exception will be thrown? Is there a way to identify which item in the collection caused the problem?

You'll get an ORMQueryExecutionException, which contains the entity causing the error, UNLESS you did a bulkupdate directly on the db of course. The actual exception is the internal exception stored in that object, so you can rethrow it and catch it again in a specific handler.

Else if nothing was saved in the database without an exception occuring , the result will only be 0.

Can this happen if there are dirty items and no exception is thrown?

No, a transaction is always aborted internally through an exception or you did the abort with Rollback, but then you know what the outcome is simple_smile

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 08-Feb-2006 15:48:12   

Thanks