tags:

views:

128

answers:

2

Ok im trying to get a MVC example page working and basically query where a certain id is specified but i'm fairly new to it all and after an hour of trying to figure this out im hoping of you can help me!!

code below is a method from my taskController.cs that is called via /tasks/complete/2

//mark task as complete
    public ActionResult Complete(int id)
    {
        IEnumerable<task> tasks = from t in db.tasks where t.taskID = id select t;


        foreach (task myTask in tasks)
        {
            myTask.isComplete = true;
        }
        db.SubmitChanges();

        return RedirectToAction("Index");
    }
+10  A: 

While the terms might sound similar, it's important to remember that LINQ is not SQL. Try using double equals for comparison:

 IEnumerable<task> tasks = from t in db.tasks where t.taskID == id select t;
Joel Potter
19 seconds, blah! :)
leppie
thank you, i thought it may be something simple that i'd overlooked - appreciate the help
Andi
didn't "=" throw an exception? Does for me.
hunter
+3  A: 

try "==" for "where t.taskID == id"

Ian Suttle
It has been said...
leppie
He probably starting writing at the same time but does it really need commenting on?
Andi
lol, that's exactly what happened.
Ian Suttle