Add System.Transactions framework
Please, provide support for System.Transactions. This would allow to use transactions (include distributed transactions) in .NET Core applications with WCF Services.
Is there any indication other than "Future Milestone" as to when we can expect this functionality? I am trying to port the AMQP.NET Lite (https://github.com/Azure/amqpnetlite) library, and it has a dependency on System.Transactions. Without this library I fear that I am unable to continue my porting of AMQP.
any updates on this?
I also need support for transactions... what real world business middle tier framework would NOT support transactions, may I ask?
There are currently no plans to port this technology to .NET Core. However, this doesn't mean that we'll never port it but as it stands we haven't seen many requests for it yet.
Here is another request for it. Totally follow @trailheadtechnology argumentation.
We follow an architecture pattern where transactional boundaries are determined in the business logic layer, not the data access layer. Since the business layer is not aware of database connections, we cannot use connection based transaction APIs. As long as TransactionScope is not available in .NET Core we will have not choice but to stay with classic .NET.
Please bring this api into .Net Core. It is an essentail part of every business application I've been part of for years. It is also one of the coolest pieces of functionality in .Net.
I think this is one of must have. I am not sure how one manage distributed transaction encompassing multiple components without System.Transaction.
This seems like an essential feature for .NET Core. I'm not sure why it isn't being more seriously considered as a must-have. Please add my name to the list of people who need it.
Ehm... One thing that I never expected to be not supported. Not that I use distributed transactions extensively, but they do have their use cases, especially when data is distributed into multiple databases or other data sources.
A simple example could be users store and users data store. Users store works with Identity server and stores User info, encrypted passwords, etc. It usually is separated from actual user data and when we need to delete user, we want to do that in a transactional way: either delete everything or leave everything in place and fix encountered errors.
Another similar situation, just with updates: at the moment we have to update some of our entities Id format, because of changed application requirements. And data using those ids is distributed throughout quite a few data sources, which are even different types of databases. I'd like to do that in a transactional way for sure. Either update everywhere or fail and leave everything in place. And all of the databases support 2PC transactions.
But without transactions support, it's a nasty va bank situation: we have to make sure the code works 100% as it is supposed and hope that no magic, nor network errors are going to happen. If anything, we have to restore backups and hope for the best up until we get it right.
I understand that most of the operations should be idempotent, but sometimes the whole data set needs to be updated in a reliable manner.
Therefore, looking at the business value transactions create, I think they are quire crucial.
Of course, if there would be alternative implementation for System.Transactions, that might be sufficient. But at the moment, I guess there is nothing out there, am I right?
Just wanted to drop another request for this. It's the only thing holding my ASP.NET project from being able to target core.
For me there are two separate aspects, both important:
-
Support for distributed transactions.
-
Support for "Ambient Transactions".
-
is important for architectural reasons, as it allows me to have my business logic define transactional boundaries without being tightly coupled to the data access layer.
Maybe the two concepts should be separated? Would allow for easier portability.
Why are we waiting?
Just realized that transaction scope was not implemented in core 1.0.0. Since I'm already in the middle of building a decent-sized app in core, is there a way to "simulate" transaction scope? Currently I have two different EF contexts (different DBs but same mssql server) and need to make sure that SaveChanges on both work (as well as some biz logic in between that needs to be correct). If either SaveChanges fails and/or biz logic is incorrect, need the entire "transaction" to be rolled back.
I'm thinking of using two explicit transactions, where one is nested inside the other. Something like the below:
using (var transactionA = contextA.Database.BeginTransaction())
{
contextA.SaveChanges();
// some biz logic here. if logic fails, throws exception
using (var transactionB = contextB.Database.BeginTransaction())
{
contextB.SaveChanges();
transactionB.Commit();
}
transactionA.Commit();
}
Is the above ok to "simulate" transaction scope-- making sure the commits are at the very end-- until distributed transactions gets implemented?
I resolved the issues as follows
context.Database.BeginTransaction();
try
{
context.SaveChanges()
// more logic
context.SaveChanges();
context.Database.CommitTransaction();
}
catch
{
context.Database.RollbackTransaction();
}
@kiwiingenuity
Not sure if you were responding to my post but if so, that would not work for me since I have two different contexts. My code snippet can still "fail" when transactionB commits ok but then transactionA fails during a commit-- meaning I can't rollback B when A fails.
Anyway I'm going to live with this at the moment since my A transaction "shouldn't fail". Hopefully they'll get transaction scope implemented in core soon.
@moraleslos Why wouldn't my idea work for you? Just set up the Begin / commit / rollback on both contexts?
@kiwiingenuity
transactionB does a commit first. If that is committed successfully, then the DB gets updated and you can't rollback. Then transactionA gets committed. If that commit fails, A rolls back but not B since that was already committed. Hence the need for distributed transactions.
@moraleslos
using (var transactionA = contextA.Database.BeginTransaction())
{
using (var transactionB = contextB.Database.BeginTransaction())
{
try
{
contextA.SaveChanges()
// more logic
contextB.SaveChanges();
contextA.Database.CommitTransaction();
contextB.Database.CommitTransaction();
}
catch
{
contextA.Database.RollbackTransaction();
contextB.Database.RollbackTransaction();
}
}
}
@kiwiingenuity
Not sure if calling rollback transaction will work here once it has already been successfully committed. So in your code, if contextA commits but then contextB fails during a commit, in your catch, contextA will fail rolling back because it has already committed. It'll probably throw an InvalidOperationException when calling rollbacktransaction on contextA. This is what I'm looking at: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
I could be wrong though and I'll try to simulate that... maybe someone else can comment on this?