我正在使用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) 我有以下查询:
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类是字符串.
有任何想法吗?这必须是一个微不足道的问题.