本文介绍了如何在linq中一起删除两个表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i have selected two tables data in a query now i want to delete this data with together
how it is possible..
if (e.CommandName == "Delete")
{
var getdata = from st in obj.admin_details
join g in obj.admin_login_tables on st.User_name equals g.user_name
where st.admin_id.Equals(id)
select new { st , g };
foreach (var t in getdata)
{
obj.admin_details.DeleteOnSubmit(t);
}
obj.SubmitChanges();
filldata();
}
in foreach loop i am going to delete data from both of tables but i dont know how to delete data from two table
thanx in advance..
推荐答案
DataClasses1DataContext obj = new DataClasses1DataContext();
int id = 1; // hard coded for testing.
var result = from ad in obj.admin_details
join alt in obj.admin_login_tables on ad.User_name equals alt.User_name
where ad.admin_id.Equals(id)
select new { admin = ad, adminlogindetail = alt };
foreach (var item in result)
{
obj.admin_details.DeleteOnSubmit(item.admin);
obj.admin_login_tables.DeleteOnSubmit(item.adminlogindetail);
}
obj.SubmitChanges();
这篇关于如何在linq中一起删除两个表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!