Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq to sql LINQ到SQL TRANSACTIONSCOPE错误_Linq To Sql - Fatal编程技术网

Linq to sql LINQ到SQL TRANSACTIONSCOPE错误

Linq to sql LINQ到SQL TRANSACTIONSCOPE错误,linq-to-sql,Linq To Sql,我在TransactionScope()和datacontext上遇到一个错误,如下所示 找不到类型或命名空间名称“TransactionScope”(是否缺少using指令或程序集引用?) 找不到类型或命名空间名称“HRPaidTimeOffDataContext”(是否缺少using指令或程序集引用?) 我必须做些什么才能在下面的代码中修复此问题 using ( TransactioScope ts = new TransactionScope()) {

我在TransactionScope()和datacontext上遇到一个错误,如下所示

找不到类型或命名空间名称“TransactionScope”(是否缺少using指令或程序集引用?)

找不到类型或命名空间名称“HRPaidTimeOffDataContext”(是否缺少using指令或程序集引用?)

我必须做些什么才能在下面的代码中修复此问题

using ( TransactioScope ts = new TransactionScope())
         {
            // Create the data context
            using (HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext())
            {
            //Now save the record
            if (this.Save(db, ref validationErrors, userAccountId))
            {
            // Commit transaction if update was successful
            ts.Complete();
            return true;
        }
        else
        {
        return false;
        }
        }
        }
是否缺少using指令或程序集引用

是的,你错过了。两个事实上

第一个:TransactionScope

在文件中(http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx)你会发现:

命名空间:System.Transactions

程序集:System.Transactions(在 System.Transactions.dll)

因此,您需要在代码顶部包含这一行:

using System.Transactions;
另一个是你自己的

HRPaidTimeOffDataContext 

因此,我无法告诉您要键入什么,但我想您现在可以管理了。

我的项目中缺少对system.Transactions的引用。添加此引用并在顶部添加using system.transactions指令后,错误消失。感谢您的关注。