delete asp_testtable
where userid='XYZ'
and SL=12
and userAmount=13
其中:
asp_testtable
是表名userid
是varchar
SL
是bigint
userAmount
是decimal
这是我遵循的三个步骤,但没有它们正在运作
第1步:
asp_testtable map = DBContext.asp_testtable.RemoveRange(DBContext.asp_testtable.Where(c => c.userid == tbuserid.Text.Trim() && c.SlNo == Convert.ToInt64(lbSlNo.Text.ToString()) && c.userAmount == Convert.ToInt16(ddluserAmount.SelectedValue.ToString()))).SingleOrDefault();
DBContext.asp_testtable.Remove(map);
第2步:
var y = (from x in asp_testtable where x.userid == tbuserid.Text.Trim() && x.SlNo == Convert.ToInt64(lbSlNo.Text) && x.userAmount == Convert.ToInt16(ddluserAmount.SelectedValue) select x.FeeMappingSlNo).First();
DBContext.asp_testtable.RemoveRange(y);
第3步:
feedetail = new asp_testtable()
{
userid = tbuserid.Text.Trim(),
SlNo = Convert.ToInt64(lbSlNo.Text),
userAmount = Convert.ToInt16(ddluserAmount.SelectedValue)
};
DBContext.asp_testtable.Remove(feedetail);
答案 0 :(得分:1)
context.asp_testtable.Select(item => item.userid == "XYZ" && item.SL = 12 &&
item.userAmount == 13).ToList().ForEach(context.asp_testtable.DeleteObject);
context.SaveChanges();
找到相关项目并使用DeleteObject
答案 1 :(得分:0)
试试这个:
string DeleteStatement = "DELETE FROM asp_testtable " +
"WHERE userid = 'XYZ' AND SL=12 AND userAmount=13 ";
yourcontext.Database.SqlQuery(DeleteStatement);