【问题标题】:can anyone help me i have problem with this message below谁能帮助我我对下面的这条消息有疑问
【发布时间】:2020-10-15 09:49:18
【问题描述】:
namespace EmployeeService.Controllers
{
    public class EmployeeController : ApiController
    {
        public IEnumerable<Customer> Get()
        {
            using (Test_DBEntities test = new Test_DBEntities())
            {
                return test.Customers.tolist();
            }
        }
    }
}

注意:EmployeeDataAccess.Test_DBEntitiesusing 语句中使用的类型必须可隐式转换为 System.IDisposable

【问题讨论】:

  • 请正确格式化您的代码,click here to learn how
  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现它所需的最短代码在问题本身。没有清晰的问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Reproducible example
  • 标题不是您帖子的一部分。标题应该总结您的问题,但帖子本身必须在没有标题的情况下有意义。

标签: asp.net api web


【解决方案1】:

你的Test_DBEntities没有实现System.IDisposable所以你不能把它放在using语句中,删除它,错误就会消失。

namespace EmployeeService.Controllers {
   public class EmployeeController: ApiController {
       public IEnumerable Get() {
           Test_DBEntities test = new Test_DBEntities();
           return test.Customers.tolist();
       }
   }
}

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多