This commit is contained in:
sunkaixuan
2017-05-21 22:33:21 +08:00
parent 23a94e92dc
commit 3ed80f6bca
7 changed files with 129 additions and 9 deletions

12
OrmTest/Demo/Delete.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
class Delete
{
}
}

12
OrmTest/Demo/Insert.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
class Insert
{
}
}

77
OrmTest/Demo/Query.cs Normal file
View File

@@ -0,0 +1,77 @@
using OrmTest.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
public class Query
{
public static void Init()
{
Easy();
Page();
Where();
Join();
Funs();
Select();
}
public static void Easy()
{
var db = GetInstance();
var getAll = db.Queryable<Student>().ToList();
var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
var getByFuns = db.Queryable<Student>().Where(it => NBORM.IsNullOrEmpty(it.Name)).ToList();
}
public static void Page()
{
}
public static void Where()
{
var db = GetInstance();
//join
var list = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
})
.Where<School>(sc => sc.Id == 1)
.Where<Student>(st => st.Id == 1)
.Where<Student, School>((st, sc) => st.Id == 1 && sc.Id == 2).ToList();
//SELECT [st].[Id],[st].[SchoolId],[st].[Name],[st].[CreateTime] FROM [Student] st
//Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] )
//WHERE ( [sc].[Id] = @Id0 ) AND ( [st].[Id] = @Id1 ) AND (( [st].[Id] = @Id2 ) AND ( [sc].[Id] = @Id3 ))
}
public static void Join()
{
}
public static void Funs()
{
}
public static void Select()
{
}
public static SqlSugarClient GetInstance()
{
SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
db.Ado.IsEnableLogEvent = true;
db.Ado.LogEventStarting = (sql, pars) =>
{
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
Console.WriteLine();
};
return db;
}
}
}

12
OrmTest/Demo/Update.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
class Update
{
}
}

View File

@@ -56,6 +56,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Demo\Delete.cs" />
<Compile Include="Demo\Insert.cs" />
<Compile Include="Demo\Query.cs" />
<Compile Include="Demo\Update.cs" />
<Compile Include="Models\ViewModelStudent.cs" />
<Compile Include="PerformanceTesting\ChloeORMPerformance.cs" />
<Compile Include="PerformanceTesting\PerformanceBase.cs" />
@@ -90,9 +94,7 @@
<Name>SqlSugar</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Demo\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -17,7 +17,7 @@ namespace OrmTest
{
static void Main(string[] args)
{
/***Unit Test***/
///***Unit Test***/
//new Field(1).Init();
//new Where(1).Init();
//new Method(1).Init();
@@ -25,16 +25,16 @@ namespace OrmTest
//new SingleQuery(1).Init();
//new SelectQuery(1).Init();
//new AutoClose(1).Init();
new Insert(1).Init();
//new Insert(1).Init();
//new Delete(1).Init();
//new Update(1).Init();
//new Mapping(1).Init();
/***Performance Test***/
///***Performance Test***/
//new SqlSugarPerformance(100).Select();
//Demo
/***Demo***/
OrmTest.Demo.Query.Init();
}
}
}

View File

@@ -44,6 +44,11 @@ namespace SqlSugar
QueryBuilder.Parameters.AddRange(pars);
return this;
}
public ISugarQueryable<T> AddParameters(SugarParameter par)
{
QueryBuilder.Parameters.Add(par);
return this;
}
public ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left)
{
@@ -222,8 +227,8 @@ namespace SqlSugar
{
var whereIndex = QueryBuilder.WhereIndex;
string parameterName = this.SqlBuilder.SqlParameterKeyWord + "InPara" + whereIndex;
this.AddParameters(new SugarParameter(parameterName, inValues[0]));
this.Where(string.Format(QueryBuilder.InTemplate, filed, parameterName));
this.AddParameters(new SqlParameter(parameterName, inValues[0]));
QueryBuilder.WhereIndex++;
}
else