【问题标题】:Enumeration yielded no results in WEB API枚举在 WEB API 中没有产生任何结果
【发布时间】:2015-08-24 18:42:44
【问题描述】:

我有一个简单的代码。

    public IHttpActionResult Get()
    {
        using (var db = new AppDBContext())
        {
            var task = (from act in db.Activities select act);
            return Ok(task.ToList());
        }
    }

当我调试时,我得到了Enumeration yielded no results,但是当我在数据库中执行它时有 200 条记录。

【问题讨论】:

    标签: asp.net-mvc linq asp.net-web-api


    【解决方案1】:

    我犯了一个愚蠢的错误。

    我的代码错误

        public AppDBContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
            Configuration.ProxyCreationEnabled = false;
            Configuration.LazyLoadingEnabled = false;
        }
    

    我认为DefaultConnection 是一个连接字符串。但是当我将其更改为我的数据库名称 TaskFiveDB4 时,现在一切都很好了。

    正确的代码

        public AppDBContext()
            : base("TaskFiveDB4", throwIfV1Schema: false)
        {
            Configuration.ProxyCreationEnabled = false;
            Configuration.LazyLoadingEnabled = false;
        }
    

    【讨论】:

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