一、删除记录
1—原始
using(dbEntities db=new dbEntities())
{
try
{
T_User instance = (from n in db.T_User.Where(n => n.FacctId == accountId) select n).FirstOrDefault();
if(instance!=null){
db.T_User.Remove(instance);
db.SaveChanges();
}
catch (Exception ex) {
this._errContent = "ERR: [ 4008 ]" + ex.Message;
}
}
2—改良
using(dbEntities db=new dbEntities())
{
try
{
db.T_Biz_AcctOwn.Attach(inRecd);
db.T_Biz_AcctOwn.Remove(inRecd);
db.SaveChanges();
}
catch (Exception ex) {
this._errContent = "ERR: [ 4019 ]" + ex.Message;
}
}
注意:inRecd实体所有必录字段必须有值!!
二、Linq语法
1—排序
① 单条件单次升序:OrderBy;
② 单条件单次降序:OrderByDescending;
③ 多次升序:OrderBy→ThenBy→ThenBy;
④ 多次降序:OrderByDescending→ThenByDescending→ThenByDescending;
⑤ 先升序再降序再升序:OrderBy→ThenByDescending→OrderBy;