Cannot implicitly convert type 'string' to 'integer'

Here is MyCode:

public ActionResult Index()
{
    var EmployeerId = SessionPersister.Email_ID;
    //Convert.ToInt32(EmployeerId);
    int.Parse(EmployeerId);
    db.Job_Det.OrderByDescending(j => j.Job_ID).ToList().Where(x => x.Employeer_ID = EmployeerId);
    return View();
}

i tried many conversion methods..but i am failed to covert the above string to integer.

Jon Skeet
people
quotationmark

Just calling Convert.ToInt32(EmployeerId) or int.Parse(EmployeerId) doesn't change the type of EmployeerId - both methods will return a value that you'd need to store in a new variable.

You're also not doing anything with your query result at the moment - and by calling ToList() before the Where call, you're fetching all the data and then filtering locally, which is a bad idea.

Finally, in your query you're trying to assign a value instead of comparing it; you want the == operator instead of =.

I suspect you want something like:

public ActionResult Index()
{
    string employerIdText = SessionPersister.Email_ID;
    int employerId = int.Parse(employerIdText);
    var jobs = db.Job_Det
        .OrderByDescending(j => j.Job_ID)
        .Where(x => x.Employeer_ID == employerId)
        .ToList();
    return View(jobs);
}

people

See more on this question at Stackoverflow