protected void TryClearCach(string exe) { if (Instance == null) { return; } long id = Convert.ToInt64(Instance.Eval(keyName)); string cachKey; if (CachResult(out cachKey)) { var list = (List <T>)MemCach.GetCach(cachKey); if (list != null && list.Count > 0) { this._selSql = string.Empty; var oldorderbyList = orderByList; var oldselPara = selPara; orderByList = new List <DBOrderby>(); var obj = LockHerper.GetLocker("loadall_" + this.tabName); try { switch (exe) { case "add": { var t = this.WhereEq(keyName, id).ExecuteEntity(); if (t != null) { lock (obj) { list.Add(t); } } break; } case "del": { var t = list.Find(p => Convert.ToInt64(p.Eval(keyName)) == id); if (t != null) { lock (obj) { list.Remove(t); } } break; } case "update": { var t = list.Find(p => Convert.ToInt64(p.Eval(keyName)) == id); var newt = this.WhereEq(keyName, id).ExecuteEntity(); if (t != null) { lock (obj) { t = newt; } } else { lock (obj) { list.Add(newt); } } break; } } } finally { orderByList = oldorderbyList; selPara = oldselPara; _selSql = string.Empty; } } //MemCach.RemoveCachItem(cachKey); } }
public List <T> ExecuteList() { string cachKey; bool cach = CachResult(out cachKey); if (cach) { object o = MemCach.GetCach(cachKey); if (o != null) { return((List <T>)o); } else { var obj = LockHerper.GetLocker("loadall_" + this.tabName); lock (obj) { o = MemCach.GetCach(cachKey); if (o != null) { return((List <T>)o); } var alllist = LoadAll(); MemCach.AddCach(cachKey, alllist, 1000); return(alllist); } } } List <T> result = new List <T>(); Database DB = DatabaseFactory.CreateDatabase(database); StringBuilder sb = new StringBuilder(); selPara.ForEach(s => { string[] sus = s.First.Split('$'); if (s.Second.Trim().Equals("in")) { sb.AppendFormat(" And {0}{1}({2})", sus[0], s.Second, s.Thrid); } else { sb.AppendFormat(" And {0}{1}@{0}{2}", sus[0], s.Second, (sus.Length > 1 ? sus[1] : "")); } }); if (orderByList != null && orderByList.Count > 0) { sb.AppendLine(" order by "); foreach (var orderby in orderByList) { sb.AppendFormat("{0} {1},", orderby.OrderbyColumnName, orderby.OrderbyDirection.ToString()); } sb.Remove(sb.Length - 1, 1); } DbCommand cmd = DB.GetSqlStringCommand(string.Format(SelSql, sb.ToString())); selPara.ForEach(s => { if (s.Second.Trim().Equals("in")) { return; } DbParameter para = cmd.CreateParameter(); para.DbType = GetDbType(s.Thrid.GetType()); string[] sus = s.First.Split('$'); para.ParameterName = "@" + sus[0] + (sus.Length > 1 ? sus[1] : ""); para.Value = s.Thrid; cmd.Parameters.Add(para); }); var ds = DB.ExecuteDataSet(cmd); if (ds.Tables.Count > 0) { Action <T, object>[] funs = null; var table0 = ds.Tables[0]; for (int i = 0; i < table0.Rows.Count; i++) { result.Add(ParseDataRow(table0.Rows[i], ref funs)); } //result = table0.AsEnumerable().Select(p => ParseDataRow(p,ref funs)).ToList(); } ////这里可以优化下,采用断线对象 //using (IDataReader dr = DB.ExecuteReader(cmd)) //{ // List<string> cols = null; // while (dr.Read()) // { // T t = ParseDataReader(dr,ref cols); // result.Add(t); // } //} return(result); }