我正在使用 MVC 4,我必须使用 Code First 迁移更新我的数据库。我要做的是从数据库表中选择记录,并将它们插入到用户可以选择的下拉列表中。
我有一个我不明白的错误:
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);
}