码复位SQL表的数据:如何,而在交易
BusinessLayer:
// an array of type int with 3 values is present
foreach(var item in list)
{
//Pseudocode incoming
Query_DoSomethingWithItem(item.Identifier, myArray)
}
DAL:
DoSomethingWithItem(long id, int[] theArray)
{
using(var scope = new TransactionScope()
{
// using SqlConnection
// fill command-parameter which makes use of a user-defined-table, which represents an array of integers.
// Important: The underlying stored_proc WRITES to database
conn.Open();
command.ExecuteNonQuery();
scope.Complete();
}
}
=>问题是,它运行完美在第一次运行中,但在第二次运行中,UDT的int数组已经从第一次执行中填充了值。
如何在首次运行后重置UDT的数据?
我试着用TransactionScope.RequiresNew但没有区别。
编辑:这就是我想实现:
表:对象[的ObjectId,...]
表:项目[的ObjectId(FK),索引]
UDT:IntegerArrray
N项目可以属于1个对象。
我不清楚这个问题,我必须指出它是WRITE,而不是读取数据库的访问。第二次运行(foreach循环中的第二项)cmd.ExecuteNonQuery()将失败,因为user-defined-table(整数数组)已经有值。 –
我一直使用数据表来保存udt数据。不管你在DoSomethingWithItem中新建一个数据表。 – Steve