I'm working with MVC 4 and I have to update my database using Code First Migrations. What I'm trying to do is to select records from a database table, and insert them into a dropdown list where the user can select one.
I have an error that I don't understand:
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);
}