mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
-
This commit is contained in:
@@ -25,8 +25,8 @@ namespace OrmTest
|
||||
//new SingleQuery(1).Init();
|
||||
//new SelectQuery(1).Init();
|
||||
//new AutoClose(1).Init();
|
||||
//new Insert(1).Init();
|
||||
new Delete(1).Init();
|
||||
new Insert(1).Init();
|
||||
//new Delete(1).Init();
|
||||
//Performance Test
|
||||
//new SqlSugarPerformance(100).Select();
|
||||
}
|
||||
|
@@ -19,36 +19,40 @@ namespace OrmTest.UnitTest
|
||||
public void Init() {
|
||||
var db = GetInstance();
|
||||
var insertObj = new Student() { Name="jack",CreateTime=DateTime.Now };
|
||||
var insertObjs = new List<Student>() { insertObj , insertObj }.ToArray();
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
//db.MappingColumns.Add("id","dbid", "Student");
|
||||
|
||||
var s1= db.Insertable<Student>(insertObj).ToSql();
|
||||
var s1= db.Insertable(insertObj).ToSql();
|
||||
|
||||
//Insert reutrn Command Count
|
||||
var s2=db.Insertable<Student>(insertObj).ExecuteCommand();
|
||||
var s2=db.Insertable(insertObj).ExecuteCommand();
|
||||
|
||||
db.IgnoreColumns = null;
|
||||
//Only insert Name
|
||||
var s3 = db.Insertable<Student>(insertObj).InsertColumns(it => new {it.Name}).ToSql();
|
||||
var s3 = db.Insertable(insertObj).InsertColumns(it => new {it.Name}).ToSql();
|
||||
|
||||
//Ignore Name and TestId
|
||||
var s4=db.Insertable<Student>(insertObj).IgnoreColumns(it => new{ it.Name,it.TestId }).ToSql();
|
||||
var s4=db.Insertable(insertObj).IgnoreColumns(it => new{ it.Name,it.TestId }).ToSql();
|
||||
|
||||
//Ignore Name and TestId
|
||||
var s5 = db.Insertable<Student>(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||
var s5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||
|
||||
//Use Lock
|
||||
var s6 =db.Insertable<Student>(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||
var s6 =db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||
|
||||
//ToSql
|
||||
var s7= db.Insertable<Student>(insertObj).With(SqlWith.UpdLock)
|
||||
var s7= db.Insertable(insertObj).With(SqlWith.UpdLock)
|
||||
.InsertColumns(it => new { it.Name }).ToSql();
|
||||
|
||||
db.IgnoreColumns = new IgnoreComumnList();
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
//Insert List<T>
|
||||
var s8= db.Insertable<Student>(insertObjs).With(SqlWith.UpdLock).ToSql();
|
||||
var insertObjs = new List<Student>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
insertObjs.Add(new Student() { Name="name"+i });
|
||||
}
|
||||
var s8= db.Insertable(insertObjs.ToArray()).InsertColumns(it=>new{ it.Name}).With(SqlWith.UpdLock).ToSql();
|
||||
}
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
|
@@ -108,16 +108,25 @@ namespace SqlSugar
|
||||
}
|
||||
else {
|
||||
StringBuilder batchInsetrSql = new StringBuilder();
|
||||
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString);
|
||||
int i = 0;
|
||||
foreach (var columns in groupList)
|
||||
{
|
||||
var isFirst = i == 0;
|
||||
if (!isFirst) {
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
int pageSize = 200;
|
||||
int pageIndex = 1;
|
||||
int totalRecord = groupList.Count;
|
||||
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||
while (pageCount >= pageIndex) {
|
||||
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString);
|
||||
int i = 0;
|
||||
foreach (var columns in groupList.Skip((pageIndex-1)*pageSize).Take(pageSize).ToList())
|
||||
{
|
||||
var isFirst = i == 0;
|
||||
if (!isFirst)
|
||||
{
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), it.ColumnName))));
|
||||
++i;
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT "+string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), it.ColumnName))));
|
||||
++i;
|
||||
pageIndex++;
|
||||
batchInsetrSql.Append("\r\nGO\r\n");
|
||||
}
|
||||
return batchInsetrSql.ToString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user