【问题标题】:BMS_DAL.BMSDataContext type used in using statement must be implicitly convertible to "System.IDisposableusing 语句中使用的 BMS_DAL.BMSDataContext 类型必须可隐式转换为“System.IDisposable
【发布时间】:2012-08-30 19:27:17
【问题描述】:

我在 C# 程序中有这个错误

public bool Delete(ref ENTValidationErrors validationErrors, int userAccountId)
     {
         if (DBAction == DBActionEnum.Delete)
         {
             // Begin database transaction
             using (TransactionScope ts = new TransactionScope())
             {
                 // Create data context
                 using (BMSDataContext db = new BMSDataContext())
                 {
                     this.Delete(db, ref validationErrors, userAccountId);
                     if (validationErrors.Count == 0)
                     {
                         //Commit transaction since the delete was successful
                         ts.Complete();
                         return true;
                     }
                     else
                     {
                         return false;
                     }
                 }
             }
         }
         else
         {
             throw new Exception("DBAction not delete.");
         }
     }

错误发生在第二个“using 语句”上。它说 '在 using 语句中使用的 BMS_DAL.BMSDataContext 类型必须隐式转换为“System.IDisposable”'

这里一定有什么问题?

【问题讨论】:

    标签: c#


    【解决方案1】:

    错误指出BMSDataContext 没有实现IDisposable,而using 语句需要可以实现的类型。

    取出第二个using 语句,并将其替换为new

    或者,如果需要,您可以在 BMSDataContext 上实现 IDisposable。您可以阅读This Post,这可能会帮助您决定是否需要实施它。

    【讨论】:

      【解决方案2】:

      使用语句添加 System.Data.Linq

      using System.Data.Linq;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多