public void Do(ProviderType type) { string fileName = "Query"; int count = 1; SqlLam <Area> sql = new SqlLam <Area>("u", type); sql.Type = ProviderType.Oracle; GlobalConfig.UseDb(ProviderType.Oracle); Log.WriteLog(count, fileName, "生成最简单的SQL", "SqlLam<Area> sql = new SqlLam<Area>();", sql); count++; sql = new SqlLam <Area>("u"); Log.WriteLog(count, fileName, "带别名的简单SQL", "SqlLam<Area> sql = new SqlLam<Area>(\"u\");", sql); count++; sql.As("u"); Log.WriteLog(count, fileName, "带别名的简单SQL2,和上面效果一样", "SqlLam<Area> sql = new SqlLam<Area>();\r\nsql.As(\"u\");", sql); count++; sql = new SqlLam <Area>(); sql.Top(100); Log.WriteLog(count, fileName, "SQL TOP * ", "sql.Top(100);", sql); count++; sql = new SqlLam <Area>(); sql.Top(100, true); Log.WriteLog(count, fileName, "SQL TOP * 带 percent ", "sql.Top(100, true);", sql); count++; sql = new SqlLam <Area>(); sql.Select(m => m.AreaCode); Log.WriteLog(count, fileName, "SQL Select 只查一列 ", "sql.Select(m => m.F_CreatorUserId);", sql); count++; sql = new SqlLam <Area>(); sql.Select(m => new { m.AreaCode, m.AreaId, m.AreaName }); Log.WriteLog(count, fileName, "SQL Select 查多列 ", "sql.Select(m => m.F_CreatorUserId);", sql); count++; sql = new SqlLam <Area>(); sql.Top(100).Select(m => new { m.AreaCode, m.AreaId, m.AreaName }); Log.WriteLog(count, fileName, "SQL TOP 其他列 先写 TOP 再写 Select", "sql.Top(100).Select(m => new { m.F_CreatorUserId, m.F_DeleteMark, m.F_EnCode });", sql); count++; sql = new SqlLam <Area>(); sql.Select(m => new { m.AreaCode, m.AreaId, m.AreaName }).Top(100); Log.WriteLog(count, fileName, "SQL TOP 其他列 先写 Select 再写 TOP, 其结果一样", "sql.Top(100).Select(m => new { m.F_CreatorUserId, m.F_DeleteMark, m.F_EnCode });", sql); count++; sql.Clear(); sql.As("a"); sql.Where(m => !string.IsNullOrEmpty(m.AreaCode)); Log.WriteLog(count, fileName, "SQL 实现 IsNullOrEmpty 方法", "sql.Where(m => string.IsNullOrEmpty(m.AreaCode));", sql); }
public void Do(ProviderType type) { SqlLam <Test> sql = new SqlLam <Test>("u", type); //sql.Top(10); DbClient db = new DbClient(); db.Error = (s, e) => { Console.WriteLine(e.Message); }; db.Log = (s) => { Log.WriteLog(1, "Insert_Log", s.Text); }; //var list = db.GetList<Test>(sql.GetSql(), sql.GetParameters()); //foreach (var item in list) //{ // Console.WriteLine(string.Format("id: {0}, int 16: {1} , double: {2}, datetime: {3} , guid: {4}, string: {5}", item.Id, item.F_Int16, item.F_Double, item.F_DateTime, item.F_Guid, item.F_String)); //} DateTime begin = DateTime.Now; Console.WriteLine(string.Format("当前时间: {0}", begin)); //遍历入库 //for (int i = 0; i < 10000; i++) //{ // sql.Clear(); // sql.Insert(new Test()); // string insertSql = sql.GetSql(); // int count = db.ExecuteNonQuery(insertSql, sql.GetParameters()); //} //一次性入库 sql.Clear(); List <Test> list = new List <Test>(100); for (int i = 0; i < 200; i++) { list.Add(new Test()); } sql.Insert(list); string insertSql = sql.GetSql(); int count = db.ExecuteNonQuery(insertSql, sql.GetParameters()); TimeSpan ts = DateTime.Now - begin; Console.WriteLine(string.Format("共用时: {0}", ts.TotalMilliseconds)); }
public void Do(ProviderType type) { string fileName = "Config"; int count = 1; SqlLam <Area> sql = new SqlLam <Area>("a", type); Log.WriteLog(count, fileName, "特性配置表名", "SqlLam<Area> sql = new SqlLam<Area>(\"a\", type);", sql); //sql.Clear(); count++; //SqlTableEntity areaTable = new SqlTableEntity(typeof(Area), "T_Area_全局"); //GlobalConfig.AddTable(areaTable); Log.WriteLog(count, fileName, "全局配置表名", "SqlTableEntity areaTable = new SqlTableEntity(typeof(Area), \"T_Area\");GlobalConfig.Tables.Add(areaTable);", sql); //sql.Clear(); count++; Log.WriteLog(count, fileName, "全局配置表名两种方式都存在", "SqlTableEntity areaTable = new SqlTableEntity(typeof(Area), \"T_Area\");GlobalConfig.Tables.Add(areaTable);", sql); sql.Clear(); count++; sql.Select(m => m.AreaName); Log.WriteLog(count, fileName, "特性配置列名", "SqlLam<Area> sql = new SqlLam<Area>(\"a\", type);sql.Select(m => m.AreaName);", sql); sql.Clear(); count++; //areaTable.AddColumn(new SqlColumnEntity("AreaName", "F_AreaName")); //GlobalConfig.AddTable(areaTable); sql.Select(m => m.AreaName); Log.WriteLog(count, fileName, "全局配置列名", "areaTable.Columns.Add(new SqlColumnEntity(\"AreaName\", \"F_AreaName\"));", sql); sql.Clear(); count++; sql.Select(m => new { m.AreaName, m.Layer }); Log.WriteLog(count, fileName, "忽略查询列名", " sql.Select(m => new { m.AreaName, m.Layer });", sql); sql.Clear(); count++; Area a = new Area(); a.Layer = 10; a.AreaName = "测试"; sql.Insert(a, false); Log.WriteLog(count, fileName, "忽略插入列名", " sql.Insert(a);", sql); sql.Clear(); count++; a.Layer = 10; a.AreaName = "测试"; sql.Update(a, false).Where(m => m.Id); Log.WriteLog(count, fileName, "忽略修改列名", " sql.Update(a, false);", sql); sql.Clear(); count++; a.Layer = 10; a.AreaName = "测试"; sql.Update(a, m => new { m.ParentId, m.Id, m.AreaName }).Where(m => m.Id); Log.WriteLog(count, fileName, "忽略修改列名部分字段", " sql.Update(a, m => new { m.ParentId, m.Id, m.AreaName }).Where(m => m.Id);", sql); }