下面是一個簡單的Linq-to-SQL查詢,用於刪除與給定用戶ID關聯的地址記錄。它看起來是正確的,並匹配我在網上跟蹤的其他示例。但是,當我執行它時,記錄不會被刪除。並沒有返回錯誤消息。我做錯了什麼?Linq-to-Sql刪除命令不起作用
protected void Button1_Click(object sender, EventArgs e)
{
int UserID = 250;
SBMData2.SBMDataContext db = new SBMData2.SBMDataContext();
var addresses = from a in db.Addresses
where a.UserID == UserID
select a;
foreach (var address in addresses)
{
try
{
db.Addresses.DeleteOnSubmit(address);
}
catch (Exception ex)
{
Label1.Text = ex.StackTrace.ToString();
}
}
}