public virtual void Update(Partly partly, Condition condition, DbTransaction tran = null) { _entityStatus = "updated"; string setSql = ""; string whereSql = ""; if (partly != null) { var filedsArr = partly.Fields.Where(x => Resources.Keys.Contains(x)).Select(GetSetSql); setSql = partly.Fields.Any() ? string.Join(",", filedsArr) : "*"; } else { setSql = GetUpdateSetSql(); } if (condition != null) { var filedsArr = condition.Fields.Select(GetWhereSql); whereSql = string.Join(" and ", filedsArr); } else { var pk = IntrospectionManager.GetPrimaryMemberName(TableFullName); whereSql = GetWhereSql(pk); } string sql = string.Format("update {0} set {1} where {2}", Escape(TableName), setSql, whereSql); if (tran == null) { _sqlHelper.ExecuteNonQuery(sql); } else { _sqlHelper.ExecuteNonQuery(tran, sql); } }
public virtual void Load(Partly partly, Condition condition, DbTransaction tran = null) { string fields = "*"; string where = ""; if (partly != null) { var filedsArr = partly.Fields.Select(Escape); fields = partly.Fields.Any() ? string.Join(",", filedsArr) : "*"; } if (condition != null) { var filedsArr = condition.Fields.Select(GetWhereSql); where = string.Join(" and ", filedsArr); } else { throw new Exception("Condition can't be null."); } string sql = string.Format("select {2} from {0} where {1}", Escape(TableName), where, fields); Load(By.Sql(sql, tran)); }
public virtual void Update(Partly partly, DbTransaction tran = null) { Update(partly, null, tran); }
public static void TestDetail <TEntity, TEntityPool>(string title) where TEntity : Entity where TEntityPool : EntityPool { string _left = ProviderManager.GetProvider(title.ToLower()).GetLeftEscape(); string _right = ProviderManager.GetProvider(title.ToLower()).GetRightEscape(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("=======" + title + " test running======="); var lo = Activator.CreateInstance <TEntityPool>(); DbTransaction tran = lo.BeginTransaction(); #region Betch Deal ShowExecuteTime("TestSave person 1000", () => { for (int i = 0; i < 1000; i++) { dynamic person = Activator.CreateInstance <TEntity>(); person.Name = "China" + i; person.Save(tran); Console.ForegroundColor = ConsoleColor.Cyan; //Console.WriteLine("Save person " + i + " sucessfully!"); } }); ShowExecuteTime("TestListSave no id person 1000", () => { var persons = new List <TEntity>(); for (int i = 0; i < 1000; i++) { dynamic person = Activator.CreateInstance <TEntity>(); person.Name = "China" + i; persons.Add(person); } lo.SaveOnly(tran, persons); }); ShowExecuteTime("TestListSave get id person 1000", () => { var persons = new List <TEntity>(); for (int i = 0; i < 1000; i++) { dynamic person = Activator.CreateInstance <TEntity>(); person.Name = "China" + i; persons.Add(person); } lo.Save(tran, persons); }); #endregion lo.Commit(); #region One dynamic p = Activator.CreateInstance <TEntity>(); ShowExecuteTime("Load one person", () => { p.Load(By.Id(3021)); }); ShowExecuteTime("Load partly condition", () => { p.Load(Partly.Columns("Id", "Name"), Condition.Where("Id", "Name")); }); p.Name = "12中国"; ShowExecuteTime("Update one person", () => { p.Update(); }); ShowExecuteTime("Save one person", () => { p.Save(); }); ShowExecuteTime("Load by sql, person", () => { p.Load(By.Sql("select * from " + _left + "Person" + _right + " order by " + _left + "Id" + _right + " desc")); }); ShowExecuteTime("Del one person", () => p.Del()); ShowExecuteTime("Get person count", () => { //var recordCount = TEntity }); //no trans p.Load(By.Id(3021)); p.Del(); p.Update(); #endregion #region List test ShowExecuteTime("ListTest", () => { var a = lo.List("select * from " + _left + "Person" + _right + ""); //var b = lo.List<TEntity>(By.All()); // var b1 = lo.List<TEntity>(By.All(false)); //var c = lo.List<TEntity>(By.Between(1, 10)); //var c1 = lo.List<TEntity>(By.Between(1, 10, false)); //var d = lo.List<TEntity>(By.Sql("select * from " + _left + "Person" + _right + "")); //var d1 = lo.List<TEntity>(By.Sql("select " + _left + "Name" + _right + " from " + _left + "Person" + _right + "")); //var e = lo.List<TEntity>(By.Top(10)); //var e1 = lo.List<TEntity>(By.Top(10, false)); //var l = lo.List<TEntity>(By.Page(1, 10)); //var l1 = lo.List<TEntity>(By.Page(1, 10, false)); }); #endregion dynamic p1 = Activator.CreateInstance <TEntity>(); dynamic p2 = Activator.CreateInstance <TEntity>(); p2.Name = "p2n"; ShowExecuteTime("TestListSave person 2", () => lo.Save(p1, p2)); p1.Name = "p1g"; p2.Name = "p2g"; ShowExecuteTime("TestListUpate person 2", () => lo.Update(p1, p2)); ShowExecuteTime("TestListDel person 2", () => lo.Del(p1, p2)); }