mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-01 19:03:58 +08:00
-
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
<Compile Include="PerformanceTesting\SqlSugarPerformance.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
||||
<Compile Include="UnitTest\Insert.cs" />
|
||||
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
||||
|
||||
@@ -18,13 +18,13 @@ namespace OrmTest
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Unit Test
|
||||
//new Field(1).Init();
|
||||
//new Where(1).Init();
|
||||
//new Method(1).Init();
|
||||
//new JoinQuery(1).Init();
|
||||
//new SingleQuery(1).Init();
|
||||
//new SelectQuery(1).Init();
|
||||
//new AutoClose(200).Init();
|
||||
new Field(1).Init();
|
||||
new Where(1).Init();
|
||||
new Method(1).Init();
|
||||
new JoinQuery(1).Init();
|
||||
new SingleQuery(1).Init();
|
||||
new SelectQuery(1).Init();
|
||||
new AutoClose(1).Init();
|
||||
|
||||
//Performance Test
|
||||
//new SqlSugarPerformance(100).Select();
|
||||
|
||||
52
OrmTest/UnitTest/Insert.cs
Normal file
52
OrmTest/UnitTest/Insert.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.UnitTest
|
||||
{
|
||||
public class Insert : ExpTestBase
|
||||
{
|
||||
private Insert() { }
|
||||
public Insert(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
var db = GetInstance();
|
||||
var insertObj = new Student() { Name="jack",CreateTime=DateTime.Now };
|
||||
var insertObjs = new List<Student>() { insertObj }.ToArray();
|
||||
|
||||
//Insert reutrn identity
|
||||
db.Insertable<Student>(insertObj).ExecuteReutrnIdentity();
|
||||
|
||||
//Insert reutrn Command Count
|
||||
db.Insertable<Student>(insertObj).ExecuteCommand();
|
||||
|
||||
//Only insert Name
|
||||
db.Insertable<Student>(insertObj).InsertColumns(it => new object[] { it.Name}).ExecuteReutrnIdentity();
|
||||
|
||||
//Ignore Name and TestId
|
||||
db.Insertable<Student>(insertObj).IgnoreColumns(it => new object[] { it.Name,it.TestId }).ExecuteReutrnIdentity();
|
||||
|
||||
//Use Lock
|
||||
db.Insertable<Student>(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||
|
||||
//ToSql
|
||||
db.Insertable<Student>(insertObj).With(SqlWith.UpdLock).InsertColumns(it => new object[] { it.Name }).ToSql();
|
||||
|
||||
//Insert List<T>
|
||||
db.Insertable<Student>(insertObjs).With(SqlWith.UpdLock).ExecuteCommand();
|
||||
}
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection=true });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user