我有这个简单的代码,但它显示了错误。我不知道我错在哪里。
我在最后一行显示错误..“deleteonsubmit”
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);
最佳答案
DeleteOnSubmit
只接受一个对象。您正在将IEnumerable<login>
传递给它。改为使用DeleteAllOnSubmit
,或从结果集合中选择单个对象,如下所示:
var remove = (from aremove in db.logins
where aremove.username == userNameString
&& aremove.Password == pwdString
select aremove).FirstOrDefault();
if(remove != null)
{
db.logins.DeleteOnSubmit(remove);
}