Best practice for Rollback with EF and Firebird

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Best practice for Rollback with EF and Firebird

Nikolaus Kern

Hello,

 

what is the best practice to rollback a failed statement with EF?

 

1.       Working with an entity in a context

2.       Putting a raw SQL statement to the database via the context

 

Is it really neccesssary to get transaction before context:SaveChanges() in order to rollback?

 

Thanks

 

Niko


------------------------------------------------------------------------------

_______________________________________________
Firebird-net-provider mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for Rollback with EF and Firebird

Jiří Činčura-2
> Is it really neccesssary to get transaction before context:SaveChanges()
> in
> order to rollback?

Yes, if you want to rollback manually. OTOH if there's an error while
processing the data, the rollback is automatic. Also take into account
that the transaction is only in database, not in context.

--
Mgr. Jiří Činčura
Independent IT Specialist

------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for Rollback with EF and Firebird

Nikolaus Kern
Hello Jiri,

thanks for the fast response.

I still have troubles arround clearing the context after an error happend on the database. I loop through N entities and modify them. The 3rd creates an error on the database which is reported back in an exception. Now the 4th and ongoing context.SaveChanges() will fail with the same error - but without having the problem at all.

In my understanding the error stucks inside the context and I need to clean it up.

Your comment "...is only in database, not in context" indicates that something needs to be done here: But what?

Thanks

Niko

-----Ursprüngliche Nachricht-----
Von: Jiří Činčura [mailto:[hidden email]]
Gesendet: Dienstag, 13. September 2016 18:22
An: [hidden email]
Betreff: Re: [Firebird-net-provider] Best practice for Rollback with EF and Firebird

> Is it really neccesssary to get transaction before
> context:SaveChanges() in order to rollback?

Yes, if you want to rollback manually. OTOH if there's an error while processing the data, the rollback is automatic. Also take into account that the transaction is only in database, not in context.

--
Mgr. Jiří Činčura
Independent IT Specialist

------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for Rollback with EF and Firebird

Jiří Činčura-2
> Your comment "...is only in database, not in context" indicates that
> something needs to be done here: But what?

You need to fix the problem in entity (or detach it, if you just want to
throw it away).

--
Mgr. Jiří Činčura
Independent IT Specialist

------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider