LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

后端 未结 11 2038
花落未央
花落未央 2020-11-22 10:41

I\'m migrating some stuff from one mysql server to a sql server but i can\'t figure out how to make this code work:

using (var context = new Context())
{
            


        
11条回答
  •  逝去的感伤
    2020-11-22 11:13

    In MVC, assume you are searching record(s) based on your requirement or information. It is working properly.

    [HttpPost]
    [ActionName("Index")]
    public ActionResult SearchRecord(FormCollection formcollection)
    {       
        EmployeeContext employeeContext = new EmployeeContext();
    
        string searchby=formcollection["SearchBy"];
        string value=formcollection["Value"];
    
        if (formcollection["SearchBy"] == "Gender")
        {
            List emplist = employeeContext.Employees.Where(x => x.Gender == value).ToList();
            return View("Index", emplist);
        }
        else
        {
            List emplist = employeeContext.Employees.Where(x => x.Name == value).ToList();
            return View("Index", emplist);
        }         
    }
    

提交回复
热议问题