相关疑难解决方法(0)

LINQ to Entities无法识别MVC 4中的方法'System.String ToString()'方法

我正在使用MVC 4,我必须使用Code First Migrations更新我的数据库.我要做的是从数据库表中选择记录,并将它们插入下拉列表,用户可以在其中选择一个.

我有一个我不明白的错误:

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

控制器:

  public ActionResult Addnew()
        {
            var dba = new DefaultConnection();
            var query = dba.blob.Select(c => new SelectListItem
            {
                Value = c.id.ToString(),
                Text = c.name_company,
                Selected = c.id.Equals(3)
            });
            var model = new Companylist
            {
                xpto = query.AsEnumerable()
            };

            return View(model);
        }
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-mvc-4 ef-migrations

33
推荐指数
1
解决办法
5万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

asp.net-mvc-4 ×1

c# ×1

ef-migrations ×1