Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete query in Linq

I have this simple code but it shows error. I dont know where I am going wrong. It shows error in last line.

 linq_testDataContext db = new linq_testDataContext();
 var remove = from aremove in db.logins
         where aremove.username == userNameString && aremove.Password == pwdString
         select aremove;
 db.logins.DeleteOnSubmit(remove);
like image 918
Ani Avatar asked Apr 26 '10 23:04

Ani


1 Answers

DeleteOnSubmit takes a single object. You are passing an IEnumerable<login> to it. Use DeleteAllOnSubmit instead, or select a single object from your resulting collection, like this:

var remove = (from aremove in db.logins 
             where aremove.username == userNameString 
                && aremove.Password == pwdString 
             select aremove).FirstOrDefault(); 

if(remove != null)
{
    db.logins.DeleteOnSubmit(remove);
}
like image 132
Philip Daubmeier Avatar answered Sep 24 '22 16:09

Philip Daubmeier