First; any error thrown is simply swallowed by your catch not acutally  
doing anything with the Exception. Rethrow it, write it to the console or  
something to get an idea of what's wrong.

Second; if one object creation fails, should all fail? If not, I'd rewrite  
it like this:


using (var tx = new TransactionScope())
{
   try
   {
     foreach (Ticket t in tickets)
     {
       t.id = EntityUtils.generateIdentifier("TK");
       t.Create();
     }

     tx.VoteCommit();
   }
   catch
   {
     tx.VoteRollBack();
     throw;
   }
}


-Asbjørn


On Fri, 27 Nov 2009 03:40:35 +0100, JustinSpiteri  
<[email protected]> wrote:

> Gens, i have this query, i wrote an init script which basically calls
> the following piece of code several times:
>
> //TransactionScope tx = new TransactionScope();
>
> try
> {
>
> // Assign identifiers to each ticket
> foreach (Ticket t in tickets)
> {
> t.Id = EntityUtils.generateIdentifier("TK");
>
> t.CreateAndFlush();
> }
>
> // tx.VoteCommit();
> //tx.Dispose();
> }
> catch (Exception e)
> {
> // tx.VoteCommit();
> //tx.Dispose();
> }
>
> The first 85 - 90 or so ticket entity objects are persisted fine,
> however the rest simply aren't persisted, with no error thrown at all,
> as if nothing wrong happened. I've tried commenting the
> transactionscope, uncommenting it, adding a "thread.sleep" (for fear
> somethin was messing up with the timing), with no positive results.
> What i have noticed is however that if i debug manually step by step,
> the process seems to work. Anyone ever came across this issue?.
>
> Regards,
>
> Justin
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Castle Project Users" group.
> To post to this group, send email to  
> [email protected].
> To unsubscribe from this group, send email to  
> [email protected].
> For more options, visit this group at  
> http://groups.google.com/group/castle-project-users?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.


Reply via email to