Find out which entity in an entity collection caused an exception

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 01-Jun-2010 18:58:25   

Hi there,

I'm saving an entity collection into a table that has a unique constraint on it. If one of the entities contradicts the unique constraint, is there some way that I can find out which entity did so so that I can report to the user the problem value?

Cheers, Ian.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 01-Jun-2010 20:35:11   

I'm struggling to think of any sensible way to do this at the moment - the best I can come up with is to start a transaction manually, and then resave the entities one at a time until one fails, at which point you roll back the transaction - but it's hardly an efficient way to go about things.

I'll give it a bit more thought and see if the other members of the support team can come up with anything in the mean time.

Matt

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 02-Jun-2010 02:04:20   
the best I can come up with is to start a transaction manually, and then resave the entities one at a time until one fails, at which point you roll back the transaction

That's a good idea to retry them one at a time _if _there's an errror - I think that's better than nothing. Would be cool if the entity instance that caused the exception could be accessed via the exception instance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jun-2010 02:55:51   

As the exception is throw by your DB->DB Adapter, there is no much you can do in LLBLGen side, other than inspect the exception/innerException. My advise is: debug the app and trap the exception, then evaluate the exception object to see what you can use of it. Some people end parsing the exception message to identify the table, with that they can find the involved entity.

Hope helpful.

David Elizondo | LLBLGen Support Team
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 02-Jun-2010 03:35:19   

How would one find the entity given the table? The inner exception doesn't seem to have anything of use in addition to the message.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Jun-2010 08:39:45   

When you save an entityCollection, what happens behind the scenes is that it saves the entities within one by one. So it won't hurt performance in any way if you loop the collection and save the entities one by one, by your self. And you might include this in a transaction if you want to. This way you will get hold of the entity which breaks the transaction.