public partial class Delete : System.Web.UI.Page
{
private TextDataContext context = new TextDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] != null)
{
if(!IsPostBack)
{
//取主键值
string code = Request["code"].ToString();
//查出数据
Info data = context.Info.Where(p => p.Code == code).First();
//删除
//先删除外键表
var queryw = context.Work.Where(p => p.InfoCode == code);
context.Work.DeleteAllOnSubmit(queryw);
var queryf = context.Family.Where(p => p.InfoCode == code);
context.Family.DeleteAllOnSubmit(queryf);
//删除自身
context.Info.DeleteOnSubmit(data);
//提交
context.SubmitChanges();
//返回
Response.Redirect("Main.aspx");
}
}
else
{
Response.Redirect("Denglu.aspx");
}
}
}