企业库,存储过程和事务范围 [英] Enterprise library, stored procedures and transaction scope

查看:64
本文介绍了企业库,存储过程和事务范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在c#3.0应用程序中有企业库4.1.数据库是SQL Server2008.我已经在设计器中创建了一个实体类(基于基类"ObjectContext").
在这个实体中,有一个函数可以挂接到数据库的存储过程中.存储过程处理将记录插入表中.没有其他的.此表上有一些限制,可以阻止重复值出现在表中.
C#遍历代表db表中记录的对象列表.循环中的每个遍历都调用实体框架对象,该实体框架对象又调用db存储过程. (我对企业库的调用是"SaveChanges".)
我发现了一个奇怪的行为:当您尝试存储1000条记录时,这些插入之一与表上的约束冲突.我希望在这种情况下可以存储999条记录.但是,在这种情况下,不存储任何记录.好像企业库本身已将事务包裹在插入文件周围,并回滚了整个交易.我当然还没有编写任何代码来包装交易.
这里发生了什么?
感谢您的帮助...

Hi,
I have enterprise library 4.1 in a c# 3.0 app. The database is SQL Server 2008. I have created an entity class in the designer (based on base class ''ObjectContext'').
In this entity there is a function that hooks into a stored procedure on the database. The stored procedure handles the insert of a record into a table. Nothing else. There are constraints on this table to stop duplicate values appearing in the table.
The c# loops through a list of objects that represent a record in the db table. Each pass in the loop calls the entity framework object, which in turn calls the db stored procedure. (the call I make to enterprise library is ''SaveChanges'').
I have found strange behaviour : when you try and store 1000 records, and one of these inserts conflicts with the constraint on the table. I would expect that 999 records are stored in this case. However, in this case NO records are stored. It is as if enterprise library has wrapped a transaction around the inserts by itself, and has rolled back the whole deal. I certainly haven''t coded anything to wrap a transaction around this.
What is going on here?
thanks for any help...

推荐答案

EntLib的源代码可用,安装时甚至会询问您.单步执行代码或查看代码以确定正在发生的情况.我已经有一段时间没看过了,但是我相信,除非另有说明,否则EntLib会将每个调用包装在事务中.
The source code for EntLib is available, you are even asked when installing it. Step through the code or look at it to determine what is happening. I haven''t looked at it for some time now but I do believe, unless otherwise specified, EntLib will wrap each call in a transaction.


这篇关于企业库,存储过程和事务范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆