相关疑难解决方法(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万
查看次数

实体框架4/Linq:如何在查询中将DateTime转换为字符串?

我有以下查询:

from a in Products
select new ProductVM
    {
         id = a.id,
         modified = a.modified.ToString()
    }
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误:

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

modified产品表的日期时间.将modified在ProductVM类是字符串.

有任何想法吗?这必须是一个微不足道的问题.

linq-to-entities tostring entity-framework-4

23
推荐指数
2
解决办法
2万
查看次数