linq to sql 的删除一张表中的多条记录
在student表中一次删除3条记录如图我用的方法是:StudentManageDataContextumdb=newStudentManageDataContext()...
在student表中一次删除3条记录如图
我用的方法是:
StudentManageDataContext umdb = new StudentManageDataContext();
public void DeleteStudent(string studentIdStr)
{
string[] array=studentIdStr.Split(',').ToArray();
var student;
foreach (var item in array)
{
student = from s in umdb.Student
where s.S_ID == item
select s;
umdb.Student.DeleteOnSubmit(student);
umdb.SubmitChanges();
}
}
这太差了要是一次删除100条那还得了。但我改写成访sql形式的报错:
var studentList = from s in umdb.Student
where s in s.S_ID
select s;
请问下linq to sql 中用in 查询数据怎么个写法 展开
我用的方法是:
StudentManageDataContext umdb = new StudentManageDataContext();
public void DeleteStudent(string studentIdStr)
{
string[] array=studentIdStr.Split(',').ToArray();
var student;
foreach (var item in array)
{
student = from s in umdb.Student
where s.S_ID == item
select s;
umdb.Student.DeleteOnSubmit(student);
umdb.SubmitChanges();
}
}
这太差了要是一次删除100条那还得了。但我改写成访sql形式的报错:
var studentList = from s in umdb.Student
where s in s.S_ID
select s;
请问下linq to sql 中用in 查询数据怎么个写法 展开
3个回答
展开全部
直接用delete不行吗!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public
void
DeleteStudent(string
studentIdStr)
{
string[]
array=studentIdStr.Split(',').ToArray();
using(StudentManageDataContext
db
=
new
StudentManageDataContext
())
{
var
students
=
db.Student.where(stus=>array.Contains(stus.S_ID));
db.Student.DeleteAllOnSubmit(students);
db.SubmitChanges();
}
}
void
DeleteStudent(string
studentIdStr)
{
string[]
array=studentIdStr.Split(',').ToArray();
using(StudentManageDataContext
db
=
new
StudentManageDataContext
())
{
var
students
=
db.Student.where(stus=>array.Contains(stus.S_ID));
db.Student.DeleteAllOnSubmit(students);
db.SubmitChanges();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询