【发布时间】:2013-08-16 12:13:52
【问题描述】:
我正在使用 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);
}
【问题讨论】:
-
this answer 应该可以解决问题
-
或者直接使用 LinqToObjects。
-
解决了!!非常感谢
标签: c# asp.net asp.net-mvc asp.net-mvc-4 entity-framework-migrations