关于Entity Framework和TransactionScope的问题
在使用事务的时候发生了问题。
void a(){
using (var trans = new TransactionScope())
{
b(model1);
c(model2);
trans.Complete();
}
}
void b(XX model){
using(var db = new myContext()){
……
db.Database.ExecuteSqlCommand(sql,args);
d(sql);
}
}
void c(XX model){
using(var db = new myContext()){
db.Database.ExecuteSqlCommand(sql,args);
d(sql);
}
}
//记录相关sql,这张表不需要用ExecuteSqlCommand执行
void d(string sql){
using(var db = new myContext()){
db.XXX.Add(new xxx{
sql = sql
});
db.SaveChanges();
}
}
现在的情况是这样的,当我b、c有一个执行失败时,d里面用Add插入的内容的确回滚了,但是b、c却是即时插入,不在事务中,没有办法回滚。
相关推荐
Packt.WCF.4.5.Multi-Layer.Services.Development.with.Entity.Framework.Dec.2012
This book is a step-by-step tutorial to guide you through learning WCF, Entity Framework, LINQ, and LINQ to Entities. You will be guided to create six WCF and Entity Framework solutions from scratch, of which three are multi-layered real-world WCF service solutions, so you will not only be reading, but also be coding through the book, to gain practical experience of WCF and Entity Framework. Various test clients will be associated with each solution and all solutions can be built and run independently of other solutions. Clear instructions and relevant screenshots will make sure you won't get lost in the world of WCF and Entity Framework. Configuration files, host applications, test clients, and WCF services for each solution will also be available for download for you to examine, modify, and debug from the outside in. The book focuses on the essentials of using WCF and Entity Framework, rather than providing a reference to every single possibility. It leaves the reference material online where it belongs, and concentrates instead on practical examples, code, and advice. What will you learn from this book Create a WCF service without using the built-in WCF templates so you can understand what's going on under the hood. Host a WCF service in IIS Express, ASP.NET Development Server, managed applications, IIS, and Windows Service. Explore and learn different debugging options for a WCF service. Build a multi-layer real-world WCF service from scratch to understand every layer of a WCF service and apply it to your real work. Learn basic and advanced concepts and features of Entity Framework, LINQ, and LINQ to Entities. Apply LINQ to Entities to the data access layer of a WCF service with Self Tracking Entities. Control concurrent updates to the database with WCF and LINQ to Entities. Add distributed transaction support to a WCF service. Understand various security settings of WCF, and host a WCF service with Basic Authentication, SSL, and Windows Authentication. Explore extension points of WCF and extend a WCF service with custom behaviors.
c# c sharp 数据库 操作 类 总结
c sharp 数据库 操作 类 总结了各种数据库操作,将会大大提高软件开发的效率。
在.net中如何使用事务
我在开发中用的事务代码,在。net中使用事务让程序更规范,更安全。
服务器端数据访问.rar_c#服务器_服务器_服务端
服务器端数据访问
ASP.NET 数据插入与更新
介绍ASP.NET如何向数据库插入和更新数据.


