我正在使用MVC4,我必须使用代码优先迁移来更新我的数据库.我试图做的是从数据库表中 Select 记录,并将它们插入一个下拉列表中,用户可以在其中 Select 一个.
我有一个我不明白的错误:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
Controller:个
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);
}