mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update MySql
This commit is contained in:
parent
321cc01198
commit
41136bbba1
6
Src/Asp.Net/MySqlTest/App.config
Normal file
6
Src/Asp.Net/MySqlTest/App.config
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
13
Src/Asp.Net/MySqlTest/Config.cs
Normal file
13
Src/Asp.Net/MySqlTest/Config.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Config
|
||||||
|
{
|
||||||
|
public static string ConnectionString = "server=localhost;Database=SqlSugarTest;Uid=root;Pwd=root";
|
||||||
|
}
|
||||||
|
}
|
1
Src/Asp.Net/MySqlTest/DataBase/script.sql
Normal file
1
Src/Asp.Net/MySqlTest/DataBase/script.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
346
Src/Asp.Net/MySqlTest/Demos/1_Query.cs
Normal file
346
Src/Asp.Net/MySqlTest/Demos/1_Query.cs
Normal file
@ -0,0 +1,346 @@
|
|||||||
|
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 : DemoBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Easy();
|
||||||
|
Page();
|
||||||
|
Where();
|
||||||
|
Join();
|
||||||
|
Funs();
|
||||||
|
Select();
|
||||||
|
Ado();
|
||||||
|
Group();
|
||||||
|
Sqlable();
|
||||||
|
Tran();
|
||||||
|
StoredProcedure();
|
||||||
|
Enum();
|
||||||
|
Simple();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Simple()
|
||||||
|
{
|
||||||
|
//SqlSugarClient
|
||||||
|
var db = GetInstance();
|
||||||
|
var student1 = db.Queryable<Student>().InSingle(1);
|
||||||
|
|
||||||
|
//get SimpleClient
|
||||||
|
var sdb = db.SimpleClient;
|
||||||
|
var student2 = sdb.GetById<Student>(1);
|
||||||
|
sdb.DeleteById<Student>(1);
|
||||||
|
sdb.Insert(new Student() { Name = "xx" });
|
||||||
|
sdb.Update<Student>(it => new Student { Name = "newvalue" }, it => it.Id == 1);//only update name where id=1
|
||||||
|
sdb.Update(new Student() { Name="newavalue" ,Id=1});//update all where id=1
|
||||||
|
|
||||||
|
//SimpleClient Get SqlSugarClient
|
||||||
|
var student3=sdb.FullClient.Queryable<Student>().InSingle(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void StoredProcedure()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//1. no result
|
||||||
|
db.Ado.UseStoredProcedure(() =>
|
||||||
|
{
|
||||||
|
string spName = "sp_help";
|
||||||
|
var getSpReslut = db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
|
||||||
|
});
|
||||||
|
|
||||||
|
//2. has result
|
||||||
|
var result = db.Ado.UseStoredProcedure<dynamic>(() =>
|
||||||
|
{
|
||||||
|
string spName = "sp_help";
|
||||||
|
return db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
|
||||||
|
});
|
||||||
|
|
||||||
|
//2. has output
|
||||||
|
object outPutValue;
|
||||||
|
var outputResult = db.Ado.UseStoredProcedure<dynamic>(() =>
|
||||||
|
{
|
||||||
|
string spName = "sp_school";
|
||||||
|
var p1 = new SugarParameter("@p1", "1");
|
||||||
|
var p2 = new SugarParameter("@p2", null, true);//isOutput=true
|
||||||
|
var dbResult = db.Ado.SqlQueryDynamic(spName, new SugarParameter[] { p1, p2 });
|
||||||
|
outPutValue = p2.Value;
|
||||||
|
return dbResult;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static void Tran()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var x=db.Insertable(new Student() { CreateTime = DateTime.Now, Name = "tran" }).ExecuteCommand();
|
||||||
|
//1. no result
|
||||||
|
var result = db.Ado.UseTran(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
var beginCount = db.Queryable<Student>().ToList();
|
||||||
|
db.Ado.ExecuteCommand("delete student");
|
||||||
|
var endCount = db.Queryable<Student>().Count();
|
||||||
|
throw new Exception("error haha");
|
||||||
|
});
|
||||||
|
var count = db.Queryable<Student>().Count();
|
||||||
|
|
||||||
|
//2 has result
|
||||||
|
var result2 = db.Ado.UseTran<List<Student>>(() =>
|
||||||
|
{
|
||||||
|
return db.Queryable<Student>().ToList();
|
||||||
|
});
|
||||||
|
|
||||||
|
//3 use try
|
||||||
|
try
|
||||||
|
{
|
||||||
|
db.Ado.BeginTran();
|
||||||
|
|
||||||
|
db.Ado.CommitTran();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
db.Ado.RollbackTran();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void Group()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var list = db.Queryable<Student>()
|
||||||
|
.GroupBy(it => it.Name)
|
||||||
|
.GroupBy(it => it.Id).Having(it => SqlFunc.AggregateAvg(it.Id) > 0)
|
||||||
|
.Select(it => new { idAvg = SqlFunc.AggregateAvg(it.Id), name = it.Name }).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
var list2 = db.Queryable<Student>()
|
||||||
|
.GroupBy(it => new { it.Id, it.Name }).Having(it => SqlFunc.AggregateAvg(it.Id) > 0)
|
||||||
|
.Select(it => new { idAvg = SqlFunc.AggregateAvg(it.Id), name = it.Name }).ToList();
|
||||||
|
|
||||||
|
// group id,name take first
|
||||||
|
var list3 = db.Queryable<Student>()
|
||||||
|
.PartitionBy(it => new { it.Id, it.Name }).Take(1).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
//SQL:
|
||||||
|
//SELECT AVG([Id]) AS[idAvg], [Name] AS[name] FROM[Student] GROUP BY[Name],[Id] HAVING(AVG([Id]) > 0 )
|
||||||
|
|
||||||
|
//SqlFunc.AggregateSum(object thisValue)
|
||||||
|
//SqlFunc.AggregateAvg<TResult>(TResult thisValue)
|
||||||
|
//SqlFunc.AggregateMin(object thisValue)
|
||||||
|
//SqlFunc.AggregateMax(object thisValue)
|
||||||
|
//SqlFunc.AggregateCount(object thisValue)
|
||||||
|
}
|
||||||
|
private static void Ado()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
db.Ado.BeginTran();
|
||||||
|
var t1 = db.Ado.SqlQuery<string>("select 'a'");
|
||||||
|
var t2 = db.Ado.GetInt("select 1");
|
||||||
|
var t3 = db.Ado.GetDataTable("select 1 as id");
|
||||||
|
db.Ado.CommitTran();
|
||||||
|
//more
|
||||||
|
//db.Ado.GetXXX...
|
||||||
|
}
|
||||||
|
public static void Easy()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var getAll = db.Queryable<Student>().ToList();
|
||||||
|
var getAllOrder = db.Queryable<Student>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
|
||||||
|
var getId = db.Queryable<Student>().Select(it => it.Id).ToList();
|
||||||
|
var getNew = db.Queryable<Student>().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();
|
||||||
|
var getAllNoLock = db.Queryable<Student>().With(SqlWith.NoLock).ToList();
|
||||||
|
var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
|
||||||
|
var getSingleOrDefault = db.Queryable<Student>().Single();
|
||||||
|
var getFirstOrDefault = db.Queryable<Student>().First();
|
||||||
|
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
|
||||||
|
var getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
|
||||||
|
var sum = db.Queryable<Student>().Sum(it => it.Id);
|
||||||
|
var isAny = db.Queryable<Student>().Where(it => it.Id == -1).Any();
|
||||||
|
var isAny2 = db.Queryable<Student>().Any(it => it.Id == -1);
|
||||||
|
var getListByRename = db.Queryable<School>().AS("Student").ToList();
|
||||||
|
var in1 = db.Queryable<Student>().In(it => it.Id, new int[] { 1, 2, 3 }).ToList();
|
||||||
|
var in2 = db.Queryable<Student>().In(new int[] { 1, 2, 3 }).ToList();
|
||||||
|
int[] array = new int[] { 1, 2 };
|
||||||
|
var in3 = db.Queryable<Student>().Where(it => SqlFunc.ContainsArray(array, it.Id)).ToList();
|
||||||
|
var group = db.Queryable<Student>().GroupBy(it => it.Id)
|
||||||
|
.Having(it => SqlFunc.AggregateCount(it.Id) > 10)
|
||||||
|
.Select(it => new { id = SqlFunc.AggregateCount(it.Id) }).ToList();
|
||||||
|
|
||||||
|
var between = db.Queryable<Student>().Where(it => SqlFunc.Between(it.Id, 1, 20)).ToList();
|
||||||
|
|
||||||
|
var getTodayList = db.Queryable<Student>().Where(it => SqlFunc.DateIsSame(it.CreateTime, DateTime.Now)).ToList();
|
||||||
|
}
|
||||||
|
public static void Page()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var pageIndex = 1;
|
||||||
|
var pageSize = 2;
|
||||||
|
var totalCount = 0;
|
||||||
|
//page
|
||||||
|
var page = db.Queryable<Student>().OrderBy(it => it.Id).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||||
|
|
||||||
|
//page join
|
||||||
|
var pageJoin = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
}).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||||
|
|
||||||
|
//top 5
|
||||||
|
var top5 = db.Queryable<Student>().Take(5).ToList();
|
||||||
|
|
||||||
|
//skip5
|
||||||
|
var skip5 = db.Queryable<Student>().Skip(5).ToList();
|
||||||
|
}
|
||||||
|
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((st, sc) => sc.Id == 1)
|
||||||
|
.Where((st, sc) => st.Id == 1)
|
||||||
|
.Where((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 ))
|
||||||
|
|
||||||
|
|
||||||
|
//Where If
|
||||||
|
string name = null;
|
||||||
|
string name2 = "sunkaixuan";
|
||||||
|
var list2 = db.Queryable<Student>()
|
||||||
|
.WhereIF(!string.IsNullOrEmpty(name), it => it.Name == name)
|
||||||
|
.WhereIF(!string.IsNullOrEmpty(name2), it => it.Name == name2).ToList();
|
||||||
|
}
|
||||||
|
public static void Join()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//join 2
|
||||||
|
var list = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
})
|
||||||
|
.Where(st => st.Name == "jack").ToList();
|
||||||
|
|
||||||
|
//join 3
|
||||||
|
var list2 = db.Queryable<Student, School, Student>((st, sc, st2) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id,
|
||||||
|
JoinType.Left,st.SchoolId==st2.Id
|
||||||
|
})
|
||||||
|
.Where((st, sc, st2) => st2.Id == 1 || sc.Id == 1 || st.Id == 1).ToList();
|
||||||
|
|
||||||
|
//join return List<ViewModelStudent>
|
||||||
|
var list3 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
}).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList();
|
||||||
|
|
||||||
|
//join Order By (order by st.id desc,sc.id desc)
|
||||||
|
var list4 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
})
|
||||||
|
.OrderBy(st => st.Id, OrderByType.Desc)
|
||||||
|
.OrderBy((st, sc) => sc.Id, OrderByType.Desc)
|
||||||
|
.Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
//join 2
|
||||||
|
var list4_1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id&& st.Name == "jack"
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
//The simple use of Join 2 table
|
||||||
|
var list5 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select((st,sc)=>new {st.Name,st.Id,schoolName=sc.Name}).ToList();
|
||||||
|
|
||||||
|
//join 3 table
|
||||||
|
var list6 = db.Queryable<Student, School,School>((st, sc,sc2) => st.SchoolId == sc.Id&&sc.Id==sc2.Id)
|
||||||
|
.Select((st, sc,sc2) => new { st.Name, st.Id, schoolName = sc.Name,schoolName2=sc2.Name }).ToList();
|
||||||
|
|
||||||
|
//join 3 table page
|
||||||
|
var list7= db.Queryable<Student, School, School>((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
|
||||||
|
.Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1,2);
|
||||||
|
|
||||||
|
//join 3 table page
|
||||||
|
var list8 = db.Queryable<Student, School, School>((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
|
||||||
|
.OrderBy(st=>st.Id)
|
||||||
|
.Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1, 2);
|
||||||
|
}
|
||||||
|
public static void Funs()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var t1 = db.Queryable<Student>().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList();
|
||||||
|
//SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) )
|
||||||
|
|
||||||
|
/***More Functions***/
|
||||||
|
//SqlFunc.IsNullOrEmpty(object thisValue)
|
||||||
|
//SqlFunc.ToLower(object thisValue)
|
||||||
|
//SqlFunc.string ToUpper(object thisValue)
|
||||||
|
//SqlFunc.string Trim(object thisValue)
|
||||||
|
//SqlFunc.bool Contains(string thisValue, string parameterValue)
|
||||||
|
//SqlFunc.ContainsArray(object[] thisValue, string parameterValue)
|
||||||
|
//SqlFunc.StartsWith(object thisValue, string parameterValue)
|
||||||
|
//SqlFunc.EndsWith(object thisValue, string parameterValue)
|
||||||
|
//SqlFunc.Equals(object thisValue, object parameterValue)
|
||||||
|
//SqlFunc.DateIsSame(DateTime date1, DateTime date2)
|
||||||
|
//SqlFunc.DateIsSame(DateTime date1, DateTime date2, DateType dataType)
|
||||||
|
//SqlFunc.DateAdd(DateTime date, int addValue, DateType millisecond)
|
||||||
|
//SqlFunc.DateAdd(DateTime date, int addValue)
|
||||||
|
//SqlFunc.DateValue(DateTime date, DateType dataType)
|
||||||
|
//SqlFunc.Between(object value, object start, object end)
|
||||||
|
//SqlFunc.ToInt32(object value)
|
||||||
|
//SqlFunc.ToInt64(object value)
|
||||||
|
//SqlFunc.ToDate(object value)
|
||||||
|
//SqlFunc.ToString(object value)
|
||||||
|
//SqlFunc.ToDecimal(object value)
|
||||||
|
//SqlFunc.ToGuid(object value)
|
||||||
|
//SqlFunc.ToDouble(object value)
|
||||||
|
//SqlFunc.ToBool(object value)
|
||||||
|
//SqlFunc.Substring(object value, int index, int length)
|
||||||
|
//SqlFunc.Replace(object value, string oldChar, string newChar)
|
||||||
|
//SqlFunc.Length(object value) { throw new NotImplementedException(); }
|
||||||
|
//SqlFunc.AggregateSum(object thisValue)
|
||||||
|
//SqlFunc.AggregateAvg<TResult>(TResult thisValue)
|
||||||
|
//SqlFunc.AggregateMin(object thisValue)
|
||||||
|
//SqlFunc.AggregateMax(object thisValue)
|
||||||
|
//SqlFunc.AggregateCount(object thisValue)
|
||||||
|
}
|
||||||
|
public static void Select()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
var s1 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
|
||||||
|
var s2 = db.Queryable<Student>().Select(it => new { id = it.Id, w = new { x = it } }).ToList();
|
||||||
|
var s3 = db.Queryable<Student>().Select(it => new { newid = it.Id }).ToList();
|
||||||
|
var s4 = db.Queryable<Student>().Select(it => new { newid = it.Id, obj = it }).ToList();
|
||||||
|
var s5 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Student = it, Name = it.Name }).ToList();
|
||||||
|
var s6 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
})
|
||||||
|
.OrderBy(st => st.Id, OrderByType.Desc)
|
||||||
|
.OrderBy((st, sc) => sc.Id, OrderByType.Desc)
|
||||||
|
.Select((st, sc) => new { Name = st.Name, SchoolId = sc.Id }).ToList();
|
||||||
|
}
|
||||||
|
private static void Sqlable()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var join3 = db.Queryable("Student", "st")
|
||||||
|
.AddJoinInfo("School", "sh", "sh.id=st.schoolid")
|
||||||
|
.Where("st.id>@id")
|
||||||
|
.AddParameters(new { id = 1 })
|
||||||
|
.Select("st.*").ToList();
|
||||||
|
//SELECT st.* FROM [Student] st Left JOIN School sh ON sh.id=st.schoolid WHERE st.id>@id
|
||||||
|
}
|
||||||
|
private static void Enum()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var list = db.Queryable<StudentEnum>().AS("Student").Where(it => it.SchoolId == SchoolEnum.HarvardUniversity).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
Src/Asp.Net/MySqlTest/Demos/2_Update.cs
Normal file
63
Src/Asp.Net/MySqlTest/Demos/2_Update.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
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 Update : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var updateObj = new Student() { Id = 1, Name = "jack", SchoolId = 0, CreateTime = Convert.ToDateTime("2017-05-21 09:56:12.610") };
|
||||||
|
var updateObjs = new List<Student>() { updateObj, new Student() { Id = 2, Name = "sun", SchoolId = 0 } }.ToArray();
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
//db.MappingColumns.Add("id","dbid", "Student");
|
||||||
|
|
||||||
|
|
||||||
|
//update reutrn Update Count
|
||||||
|
var t1 = db.Updateable(updateObj).ExecuteCommand();
|
||||||
|
|
||||||
|
//Only update Name
|
||||||
|
var t3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name }).ExecuteCommand();
|
||||||
|
var t3_1 = db.Updateable(updateObj).UpdateColumns(it => it=="Name").ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteCommand();
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
//Use Lock
|
||||||
|
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||||
|
|
||||||
|
//update List<T>
|
||||||
|
var t7 = db.Updateable(updateObjs).ExecuteCommand();
|
||||||
|
|
||||||
|
//Re Set Value
|
||||||
|
var t8 = db.Updateable(updateObj)
|
||||||
|
.ReSetValue(it => it.Name == (it.Name + 1)).ExecuteCommand();
|
||||||
|
|
||||||
|
//Where By Expression
|
||||||
|
var t9 = db.Updateable(updateObj).Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
|
||||||
|
//Update By Expression Where By Expression
|
||||||
|
var t10 = db.Updateable<Student>()
|
||||||
|
.UpdateColumns(it => new Student() { Name = "a", CreateTime = DateTime.Now })
|
||||||
|
.Where(it => it.Id == 11).ExecuteCommand();
|
||||||
|
|
||||||
|
//Rename
|
||||||
|
db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
//Update Student set Name='jack' Where Id=1
|
||||||
|
|
||||||
|
//Column is null no update
|
||||||
|
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
Src/Asp.Net/MySqlTest/Demos/3_Insert.cs
Normal file
58
Src/Asp.Net/MySqlTest/Demos/3_Insert.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
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 Insert:DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
|
||||||
|
var insertObj = new Student() { Name = "jack", CreateTime = Convert.ToDateTime("2010-1-1"), SchoolId = 1 };
|
||||||
|
|
||||||
|
//Insert reutrn Insert Count
|
||||||
|
var t2 = db.Insertable(insertObj).ExecuteCommand();
|
||||||
|
|
||||||
|
//Insert reutrn Identity Value
|
||||||
|
var t3 = db.Insertable(insertObj).ExecuteReutrnIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
//Only insert Name and SchoolId
|
||||||
|
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReutrnIdentity();
|
||||||
|
var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReutrnIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
//Ignore TestId
|
||||||
|
var t5 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReutrnIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
//Ignore TestId
|
||||||
|
var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReutrnIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
//Use Lock
|
||||||
|
var t8 = db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") };
|
||||||
|
var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, false/*off identity*/).ExecuteCommand();
|
||||||
|
|
||||||
|
//Insert List<T>
|
||||||
|
var insertObjs = new List<Student>();
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
insertObjs.Add(new Student() { Name = "name" + i });
|
||||||
|
}
|
||||||
|
var t10 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand();
|
||||||
|
|
||||||
|
var t11 = db.Insertable(insertObjs.ToArray()).ExecuteCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
Src/Asp.Net/MySqlTest/Demos/4_Delete.cs
Normal file
33
Src/Asp.Net/MySqlTest/Demos/4_Delete.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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 Delete:DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//by entity
|
||||||
|
var t1 = db.Deleteable<Student>().Where(new Student() { Id = 1 }).ExecuteCommand();
|
||||||
|
|
||||||
|
//use lock
|
||||||
|
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
//by primary key
|
||||||
|
var t3 = db.Deleteable<Student>().In(1).ExecuteCommand();
|
||||||
|
|
||||||
|
//by primary key array
|
||||||
|
var t4 = db.Deleteable<Student>().In(new int[] { 1, 2 }).ExecuteCommand();
|
||||||
|
|
||||||
|
//by expression
|
||||||
|
var t5 = db.Deleteable<Student>().Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
Src/Asp.Net/MySqlTest/Demos/5_CodeFirst.cs
Normal file
52
Src/Asp.Net/MySqlTest/Demos/5_CodeFirst.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
public class CodeTable
|
||||||
|
{
|
||||||
|
|
||||||
|
[SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[SugarColumn(Length = 21,OldColumnName = "Name2")]
|
||||||
|
public string Name{ get; set; }
|
||||||
|
[SugarColumn(IsNullable = true,Length =10)]
|
||||||
|
public string IsOk { get; set; }
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
public decimal Decimal { get; set; }
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime? DateTime { get; set; }
|
||||||
|
[SugarColumn(IsNullable = true,OldColumnName = "Dob")]
|
||||||
|
public double? Dob2 { get; set; }
|
||||||
|
[SugarColumn(Length =10)]
|
||||||
|
public string A { get; set; }
|
||||||
|
}
|
||||||
|
public class CodeTable2 {
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
[SugarColumn(IsIgnore =true)]
|
||||||
|
public string TestId { get; set; }
|
||||||
|
}
|
||||||
|
public class CodeFirst : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
DbType = DbType.MySql,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
InitKeyType = InitKeyType.Attribute
|
||||||
|
});
|
||||||
|
|
||||||
|
//Backup table
|
||||||
|
//db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
|
||||||
|
|
||||||
|
//No backup table
|
||||||
|
db.CodeFirst.InitTables(typeof(CodeTable),typeof(CodeTable2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
Src/Asp.Net/MySqlTest/Demos/5_DbFirst.cs
Normal file
72
Src/Asp.Net/MySqlTest/Demos/5_DbFirst.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
public class DbFirst : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//Create all class
|
||||||
|
db.DbFirst.CreateClassFile("c:\\Demo\\1");
|
||||||
|
|
||||||
|
//Create student calsss
|
||||||
|
db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\2");
|
||||||
|
//Where(array)
|
||||||
|
|
||||||
|
//Mapping name
|
||||||
|
db.MappingTables.Add("ClassStudent", "Student");
|
||||||
|
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
|
||||||
|
db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\3");
|
||||||
|
|
||||||
|
//Remove mapping
|
||||||
|
db.MappingTables.Clear();
|
||||||
|
|
||||||
|
//Create class with default value
|
||||||
|
db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\Demo\\4", "Demo.Models");
|
||||||
|
|
||||||
|
|
||||||
|
//Mapping and Attribute
|
||||||
|
db.MappingTables.Add("ClassStudent", "Student");
|
||||||
|
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
|
||||||
|
db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\Demo\\5");
|
||||||
|
|
||||||
|
|
||||||
|
//Remove mapping
|
||||||
|
db.MappingTables.Clear();
|
||||||
|
db.MappingColumns.Clear();
|
||||||
|
|
||||||
|
//Custom format,Change old to new
|
||||||
|
db.DbFirst.
|
||||||
|
SettingClassTemplate(old =>
|
||||||
|
{
|
||||||
|
return old;
|
||||||
|
})
|
||||||
|
.SettingNamespaceTemplate(old =>
|
||||||
|
{
|
||||||
|
return old;
|
||||||
|
})
|
||||||
|
.SettingPropertyDescriptionTemplate(old =>
|
||||||
|
{
|
||||||
|
return @" /// <summary>
|
||||||
|
/// Desc_New:{PropertyDescription}
|
||||||
|
/// Default_New:{DefaultValue}
|
||||||
|
/// Nullable_New:{IsNullable}
|
||||||
|
/// </summary>";
|
||||||
|
})
|
||||||
|
.SettingPropertyTemplate(old =>
|
||||||
|
{
|
||||||
|
return old;
|
||||||
|
})
|
||||||
|
.SettingConstructorTemplate(old =>
|
||||||
|
{
|
||||||
|
return old;
|
||||||
|
})
|
||||||
|
.CreateClassFile("c:\\Demo\\6");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
Src/Asp.Net/MySqlTest/Demos/6_ComplexModel.cs
Normal file
78
Src/Asp.Net/MySqlTest/Demos/6_ComplexModel.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using SqlSugar;
|
||||||
|
using OrmTest.Demo;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
public class ComplexModel : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var students = db.Queryable<CMStudent>().ToList();
|
||||||
|
if (students != null)
|
||||||
|
{
|
||||||
|
foreach (var item in students)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item.SchoolName);
|
||||||
|
if (item.SchoolSingle != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item.SchoolSingle.Name);
|
||||||
|
}
|
||||||
|
if (item.SchoolList != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item.SchoolList.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarTable("Student")]
|
||||||
|
public class CMStudent : ModelContext
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int SchoolId { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public string SchoolName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.SchoolSingle != null)
|
||||||
|
return this.SchoolSingle.Name;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public CMSchool SchoolSingle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return base.CreateMapping<CMSchool>().Single(it => it.Id == this.SchoolId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public List<CMSchool> SchoolList
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return base.CreateMapping<CMSchool>().Where(it => it.Id == this.SchoolId).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarTable("School")]
|
||||||
|
public class CMSchool
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
72
Src/Asp.Net/MySqlTest/Demos/7_Filter.cs
Normal file
72
Src/Asp.Net/MySqlTest/Demos/7_Filter.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using OrmTest.Demo;
|
||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
public class Filter : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//gobal filter
|
||||||
|
var db = GetInstance1();
|
||||||
|
|
||||||
|
var sql = db.Queryable<Student>().ToSql();
|
||||||
|
//SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE isDelete=0
|
||||||
|
|
||||||
|
var sql2 = db.Queryable<Student, School>((f, s) => new object[] { JoinType.Left, f.SchoolId == s.Id }).ToSql();
|
||||||
|
//SELECT[f].[ID],[f].[SchoolId],[f].[Name],[f].[CreateTime]
|
||||||
|
//FROM[STudent] f Left JOIN School s ON([f].[SchoolId] = [s].[Id]) WHERE f.isDelete=0
|
||||||
|
|
||||||
|
|
||||||
|
//Specify name filter
|
||||||
|
var sql3 = db.Queryable<Student>().Filter("query1").ToSql();
|
||||||
|
//SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE WHERE id>@id AND isDelete=0
|
||||||
|
|
||||||
|
|
||||||
|
//Specify key filter and disabled global filter
|
||||||
|
string key = "query1";
|
||||||
|
var sql4 = db.Queryable<Student>().Filter(key,true).ToSql();
|
||||||
|
//SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE WHERE id>@id
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SqlSugarClient GetInstance1()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
db.QueryFilter
|
||||||
|
.Add(new SqlFilterItem()
|
||||||
|
{
|
||||||
|
FilterValue = filterDb =>
|
||||||
|
{
|
||||||
|
return new SqlFilterResult() { Sql = " isDelete=0" };
|
||||||
|
},
|
||||||
|
IsJoinQuery = false
|
||||||
|
}).Add(new SqlFilterItem()
|
||||||
|
{
|
||||||
|
FilterValue = filterDb =>
|
||||||
|
{
|
||||||
|
return new SqlFilterResult() { Sql = " f.isDelete=0" };
|
||||||
|
},
|
||||||
|
IsJoinQuery = true
|
||||||
|
})
|
||||||
|
.Add(new SqlFilterItem()
|
||||||
|
{
|
||||||
|
FilterName = "query1",
|
||||||
|
FilterValue = filterDb =>
|
||||||
|
{
|
||||||
|
return new SqlFilterResult() { Sql = " id>@id", Parameters = new { id = 1 } };
|
||||||
|
},
|
||||||
|
IsJoinQuery = false
|
||||||
|
});
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
Src/Asp.Net/MySqlTest/Demos/8_JoinSql.cs
Normal file
51
Src/Asp.Net/MySqlTest/Demos/8_JoinSql.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using OrmTest.Demo;
|
||||||
|
using OrmTest.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Secure string operations
|
||||||
|
/// </summary>
|
||||||
|
public class JoinSql : DemoBase
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Where();
|
||||||
|
OrderBy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Where()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//Parameterized processing
|
||||||
|
string value = "'jack';drop table Student";
|
||||||
|
var list = db.Queryable<Student>().Where("name=@name", new { name = value }).ToList();
|
||||||
|
//Nothing happened
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OrderBy()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//propertyName is valid
|
||||||
|
string propertyName = "Id";
|
||||||
|
string dbColumnName = db.EntityProvider.GetDbColumnName<Student>(propertyName);
|
||||||
|
var list = db.Queryable<Student>().OrderBy(dbColumnName).ToList();
|
||||||
|
|
||||||
|
//propertyName is invalid
|
||||||
|
try
|
||||||
|
{
|
||||||
|
propertyName = "Id'";
|
||||||
|
dbColumnName = db.EntityProvider.GetDbColumnName<Student>(propertyName);
|
||||||
|
var list2 = db.Queryable<Student>().OrderBy(dbColumnName).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
Src/Asp.Net/MySqlTest/Demos/DemoBase.cs
Normal file
23
Src/Asp.Net/MySqlTest/Demos/DemoBase.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Demo
|
||||||
|
{
|
||||||
|
public class DemoBase
|
||||||
|
{
|
||||||
|
public static SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||||
|
db.Ado.IsEnableLogEvent = true;
|
||||||
|
db.Ado.LogEventStarting = (sql, pars) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||||
|
Console.WriteLine();
|
||||||
|
};
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
135
Src/Asp.Net/MySqlTest/Models/DataTestInfo.cs
Normal file
135
Src/Asp.Net/MySqlTest/Models/DataTestInfo.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
public class DataTestInfo
|
||||||
|
{
|
||||||
|
public DataTestInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public int Int1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public int? Int2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string String {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public decimal Decimal1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public decimal? Decimal2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public DateTime Datetime1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? Datetime2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Image1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Image2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public Guid Guid1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public Guid? Guid2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public decimal Money1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public decimal? Money2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Varbinary1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Varbinary2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public double Float1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public double? Float2 {get;set;}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
44
Src/Asp.Net/MySqlTest/Models/DataTestInfo2.cs
Normal file
44
Src/Asp.Net/MySqlTest/Models/DataTestInfo2.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
public class DataTestInfo2
|
||||||
|
{
|
||||||
|
public DataTestInfo2(){
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public Guid PK {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public bool Bool1 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public bool? Bool2 {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:
|
||||||
|
/// Default:
|
||||||
|
/// Nullable:True
|
||||||
|
/// </summary>
|
||||||
|
public string Text1 {get;set;}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
Src/Asp.Net/MySqlTest/Models/Enum.cs
Normal file
22
Src/Asp.Net/MySqlTest/Models/Enum.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
public enum SchoolEnum
|
||||||
|
{
|
||||||
|
HarvardUniversity = 0,
|
||||||
|
UniversityOfOxford = 1
|
||||||
|
}
|
||||||
|
public class StudentEnum
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public SchoolEnum SchoolId { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime? CreateTime { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsIgnore =true)]
|
||||||
|
public int TestId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
17
Src/Asp.Net/MySqlTest/Models/School.cs
Normal file
17
Src/Asp.Net/MySqlTest/Models/School.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
public class School
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
22
Src/Asp.Net/MySqlTest/Models/Student.cs
Normal file
22
Src/Asp.Net/MySqlTest/Models/Student.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
[SugarTable("STudent")]
|
||||||
|
public class Student
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int? SchoolId { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime? CreateTime { get; set; }
|
||||||
|
[SugarColumn(IsIgnore=true)]
|
||||||
|
public int TestId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
18
Src/Asp.Net/MySqlTest/Models/ViewModelStudent.cs
Normal file
18
Src/Asp.Net/MySqlTest/Models/ViewModelStudent.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.Models
|
||||||
|
{
|
||||||
|
public class ViewModelStudent:Student
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public class ViewModelStudent2
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public Student Student { get; set; }
|
||||||
|
}
|
||||||
|
}
|
116
Src/Asp.Net/MySqlTest/MySqlTest.csproj
Normal file
116
Src/Asp.Net/MySqlTest/MySqlTest.csproj
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{B72FC095-9AFA-4375-AF14-402339BAF1DF}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>MySqlTest</RootNamespace>
|
||||||
|
<AssemblyName>MySqlTest</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="MySql.Data">
|
||||||
|
<HintPath>..\SqlSugar\Lib\MySql.Data.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json">
|
||||||
|
<HintPath>..\SqlSugar\Lib\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SyntacticSugar, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\SqlServerTest\OtherDll\SyntacticSugar.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Config.cs" />
|
||||||
|
<Compile Include="Demos\1_Query.cs" />
|
||||||
|
<Compile Include="Demos\2_Update.cs" />
|
||||||
|
<Compile Include="Demos\3_Insert.cs" />
|
||||||
|
<Compile Include="Demos\4_Delete.cs" />
|
||||||
|
<Compile Include="Demos\5_CodeFirst.cs" />
|
||||||
|
<Compile Include="Demos\5_DbFirst.cs" />
|
||||||
|
<Compile Include="Demos\6_ComplexModel.cs" />
|
||||||
|
<Compile Include="Demos\7_Filter.cs" />
|
||||||
|
<Compile Include="Demos\8_JoinSql.cs" />
|
||||||
|
<Compile Include="Demos\DemoBase.cs" />
|
||||||
|
<Compile Include="Models\DataTestInfo.cs" />
|
||||||
|
<Compile Include="Models\DataTestInfo2.cs" />
|
||||||
|
<Compile Include="Models\Enum.cs" />
|
||||||
|
<Compile Include="Models\School.cs" />
|
||||||
|
<Compile Include="Models\Student.cs" />
|
||||||
|
<Compile Include="Models\ViewModelStudent.cs" />
|
||||||
|
<Compile Include="PerformanceTesting\PerformanceBase.cs" />
|
||||||
|
<Compile Include="PerformanceTesting\SqlSugarPerformance.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="UnitTest\DataTest.cs" />
|
||||||
|
<Compile Include="UnitTest\Delete.cs" />
|
||||||
|
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
||||||
|
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
||||||
|
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
||||||
|
<Compile Include="UnitTest\ExpressionTest\Where.cs" />
|
||||||
|
<Compile Include="UnitTest\Insert.cs" />
|
||||||
|
<Compile Include="UnitTest\Mapping .cs" />
|
||||||
|
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
||||||
|
<Compile Include="UnitTest\Query\SelectQuery.cs" />
|
||||||
|
<Compile Include="UnitTest\Query\SingleQuery.cs" />
|
||||||
|
<Compile Include="UnitTest\Setting\Attribute.cs" />
|
||||||
|
<Compile Include="UnitTest\Setting\AutoClose.cs" />
|
||||||
|
<Compile Include="UnitTest\Setting\MapColumn.cs" />
|
||||||
|
<Compile Include="UnitTest\Setting\MapTable.cs" />
|
||||||
|
<Compile Include="UnitTest\UnitTestBase.cs" />
|
||||||
|
<Compile Include="UnitTest\Update.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
|
||||||
|
<Project>{489bb790-226c-4fad-8d1e-51d72a7ff8e5}</Project>
|
||||||
|
<Name>SqlSugar</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="DataBase\script.sql" />
|
||||||
|
<Content Include="OtherDll\SyntacticSugar.dll" />
|
||||||
|
</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.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
BIN
Src/Asp.Net/MySqlTest/OtherDll/SyntacticSugar.dll
Normal file
BIN
Src/Asp.Net/MySqlTest/OtherDll/SyntacticSugar.dll
Normal file
Binary file not shown.
30
Src/Asp.Net/MySqlTest/PerformanceTesting/PerformanceBase.cs
Normal file
30
Src/Asp.Net/MySqlTest/PerformanceTesting/PerformanceBase.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using SyntacticSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.PerformanceTesting
|
||||||
|
{
|
||||||
|
public class PerformanceBase
|
||||||
|
{
|
||||||
|
public int count = 100;
|
||||||
|
public void Execute(string title, Action fun)
|
||||||
|
{
|
||||||
|
PerformanceTest ptef = new PerformanceTest();
|
||||||
|
ptef.SetCount(count);//执行count次
|
||||||
|
ptef.Execute(
|
||||||
|
i =>
|
||||||
|
{
|
||||||
|
fun();
|
||||||
|
|
||||||
|
},
|
||||||
|
res =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(string.Format("Execute {0} time,{1}{2}", count, title, res));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using OrmTest.Models;
|
||||||
|
|
||||||
|
namespace OrmTest.PerformanceTesting
|
||||||
|
{
|
||||||
|
public class SqlSugarPerformance : PerformanceBase
|
||||||
|
{
|
||||||
|
public SqlSugarPerformance(int eachCount)
|
||||||
|
{
|
||||||
|
this.count = eachCount;
|
||||||
|
}
|
||||||
|
public void Select()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
IsAutoCloseConnection = false
|
||||||
|
});
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
db.Queryable<Student>().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
|
||||||
|
base.Execute("sqlsuagr", () =>
|
||||||
|
{
|
||||||
|
var test = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
|
||||||
|
});
|
||||||
|
db.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
Src/Asp.Net/MySqlTest/Program.cs
Normal file
49
Src/Asp.Net/MySqlTest/Program.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using SqlSugar;
|
||||||
|
using OrmTest.Models;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using OrmTest.UnitTest;
|
||||||
|
using OrmTest.PerformanceTesting;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
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(1).Init();
|
||||||
|
// new Insert(1).Init();
|
||||||
|
// new Delete(1).Init();
|
||||||
|
// new Update(1).Init();
|
||||||
|
// new Mapping(1).Init();
|
||||||
|
// new DataTest(1).Init();
|
||||||
|
|
||||||
|
// /***Performance Test***/
|
||||||
|
// new SqlSugarPerformance(100).Select();
|
||||||
|
|
||||||
|
/***Demo***/
|
||||||
|
//OrmTest.Demo.Query.Init();
|
||||||
|
//OrmTest.Demo.Insert.Init();
|
||||||
|
//OrmTest.Demo.Delete.Init();
|
||||||
|
//OrmTest.Demo.Update.Init();
|
||||||
|
//OrmTest.Demo.DbFirst.Init();
|
||||||
|
//OrmTest.Demo.JoinSql.Init();
|
||||||
|
//OrmTest.Demo.Filter.Init();
|
||||||
|
//OrmTest.Demo.ComplexModel.Init();
|
||||||
|
OrmTest.Demo.CodeFirst.Init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
Src/Asp.Net/MySqlTest/Properties/AssemblyInfo.cs
Normal file
36
Src/Asp.Net/MySqlTest/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("MySqlTest")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("MySqlTest")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("b72fc095-9afa-4375-af14-402339baf1df")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
77
Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs
Normal file
77
Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class DataTest : UnitTestBase
|
||||||
|
{
|
||||||
|
private DataTest() { }
|
||||||
|
public DataTest(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
db.DbMaintenance.TruncateTable("DataTestInfo");
|
||||||
|
var insertObject = new DataTestInfo()
|
||||||
|
{
|
||||||
|
Datetime1 = DateTime.Now,
|
||||||
|
Datetime2 = DateTime.Now,
|
||||||
|
Decimal1 = 1,
|
||||||
|
Decimal2 = 2,
|
||||||
|
Float1 = 3,
|
||||||
|
Float2 = 4,
|
||||||
|
Guid1 = Guid.Empty,
|
||||||
|
Guid2 = null,
|
||||||
|
Image1 = new byte[] { 1, 2 },
|
||||||
|
Image2 = new byte[] { 2, 3 },
|
||||||
|
Int2 = 6,
|
||||||
|
Money1 = 7,
|
||||||
|
Money2 = 8,
|
||||||
|
Varbinary1 = new byte[] { 4, 5 },
|
||||||
|
Varbinary2 = null,
|
||||||
|
String = "string"
|
||||||
|
};
|
||||||
|
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReutrnIdentity();
|
||||||
|
var data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||||
|
if (
|
||||||
|
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
||||||
|
insertObject.Decimal1 != data.Decimal1 ||
|
||||||
|
insertObject.Float1 != data.Float1 ||
|
||||||
|
insertObject.Float2 != data.Float2 ||
|
||||||
|
insertObject.Int2 != data.Int2 ||
|
||||||
|
insertObject.Money1 != data.Money1 ||
|
||||||
|
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
|
||||||
|
insertObject.String != data.String)
|
||||||
|
{
|
||||||
|
throw new Exception("DataTest Error");
|
||||||
|
}
|
||||||
|
data.Float1= data.Float1+1;
|
||||||
|
db.Updateable(data).ExecuteCommand();
|
||||||
|
data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||||
|
if (
|
||||||
|
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
||||||
|
insertObject.Decimal1 != data.Decimal1 ||
|
||||||
|
(insertObject.Float1+1) != data.Float1 ||
|
||||||
|
insertObject.Float2 != data.Float2 ||
|
||||||
|
insertObject.Int2 != data.Int2 ||
|
||||||
|
insertObject.Money1 != data.Money1 ||
|
||||||
|
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
|
||||||
|
insertObject.String != data.String)
|
||||||
|
{
|
||||||
|
throw new Exception("DataTest Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
Src/Asp.Net/MySqlTest/UnitTest/Delete.cs
Normal file
67
Src/Asp.Net/MySqlTest/UnitTest/Delete.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using OrmTest.UnitTest;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Delete : UnitTestBase
|
||||||
|
{
|
||||||
|
private Delete() { }
|
||||||
|
public Delete(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
//by entity
|
||||||
|
var t1= db.Deleteable<Student>().Where(new Student() { Id = 1 }).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
|
||||||
|
null,
|
||||||
|
t1.Key,
|
||||||
|
null, "Delte t1 error"
|
||||||
|
);
|
||||||
|
//use lock
|
||||||
|
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
|
||||||
|
null,
|
||||||
|
t2.Key,
|
||||||
|
null, "Delte t2 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
//by primary key
|
||||||
|
var t3 = db.Deleteable<Student>().In(1).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
|
||||||
|
null,
|
||||||
|
t3.Key,
|
||||||
|
null, "Delte tt error"
|
||||||
|
);
|
||||||
|
//by primary key array
|
||||||
|
var t4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1','2') ", null, t4.Key, null, "Update t4 error");
|
||||||
|
|
||||||
|
//by expression
|
||||||
|
var t5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1)
|
||||||
|
}, t5.Key, t5.Value, "Delte t5 error");
|
||||||
|
|
||||||
|
var t6 = db.Deleteable<Student>().Where("id=@id",new { id=1}).ToSql();
|
||||||
|
base.Check(@"DELETE FROM [STudent] WHERE id=@id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@id",1)
|
||||||
|
}, t6.Key, t6.Value, "Delte t6 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Field.cs
Normal file
51
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Field.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Field : UnitTestBase
|
||||||
|
{
|
||||||
|
private Field() { }
|
||||||
|
public Field(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
FieldSingle();
|
||||||
|
FieldMultiple();
|
||||||
|
}
|
||||||
|
base.End("Filed Test");
|
||||||
|
}
|
||||||
|
private void FieldSingle()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, object>> exp = it => it.Name;
|
||||||
|
ExpressionContext expContext = GetContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.FieldSingle);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
Check(selectorValue, null, expContext.GetTranslationColumnName("Name"), null, "FieldSingle error");
|
||||||
|
}
|
||||||
|
private void FieldMultiple()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, object>> exp = it => it.Name;
|
||||||
|
ExpressionContext expContext = GetContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
Check(selectorValue, null, expContext.GetTranslationColumnName("it.Name"), null, "FieldMultiple error");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext GetContext()
|
||||||
|
{
|
||||||
|
return new SqlServerExpressionContext();//可以更换
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
612
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs
Normal file
612
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Method.cs
Normal file
@ -0,0 +1,612 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Method : UnitTestBase
|
||||||
|
{
|
||||||
|
private Method() { }
|
||||||
|
public Method(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Native methods
|
||||||
|
ExtendContainsArray();
|
||||||
|
ConvetToString();
|
||||||
|
ExtendToString();
|
||||||
|
ExtendSubstring();
|
||||||
|
ExtendDate();
|
||||||
|
|
||||||
|
//SqlFun methods
|
||||||
|
IIF();
|
||||||
|
IIF2();
|
||||||
|
#region StringIsNullOrEmpty
|
||||||
|
HasValue();
|
||||||
|
HasNumber();
|
||||||
|
StringIsNullOrEmpty();
|
||||||
|
StringIsNullOrEmpty2();
|
||||||
|
StringIsNullOrEmpty3();
|
||||||
|
StringIsNullOrEmpty4();
|
||||||
|
StringIsNullOrEmpty5();
|
||||||
|
#endregion
|
||||||
|
ToUpper();
|
||||||
|
ToLower();
|
||||||
|
Trim();
|
||||||
|
Contains();
|
||||||
|
Contains2();
|
||||||
|
ContainsArray();
|
||||||
|
StartsWith();
|
||||||
|
EndsWith();
|
||||||
|
Between();
|
||||||
|
Equals();
|
||||||
|
Equals_2();
|
||||||
|
DateIsSameByDay();
|
||||||
|
DateIsSameByType();
|
||||||
|
DateAddDay();
|
||||||
|
DateAddByType();
|
||||||
|
DateValue();
|
||||||
|
ToInt32();
|
||||||
|
ToInt64();
|
||||||
|
ToDate();
|
||||||
|
Tostring();
|
||||||
|
ToDecimal();
|
||||||
|
ToGuid();
|
||||||
|
ToDouble();
|
||||||
|
ToBool();
|
||||||
|
Substring();
|
||||||
|
Replace();
|
||||||
|
Length();
|
||||||
|
}
|
||||||
|
base.End("Method Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExtendToString()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id.ToString() == "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST([Id] AS NVARCHAR(MAX)) = @Const0 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Const0","a")
|
||||||
|
}, "ExtendToString error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConvetToString()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => Convert.ToString(it.Id) == "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST([Id] AS NVARCHAR(MAX)) = @Const0 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Const0","a")
|
||||||
|
}, "ConvetToString error");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void Length()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Length("aaaa") > 1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(LEN(@MethodConst0) > @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","aaaa"),new SugarParameter("@Const1",1)
|
||||||
|
}, "Length error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Replace()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(REPLACE(@MethodConst0,@MethodConst1,@MethodConst2) = @Const3 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1","a") , new SugarParameter("@MethodConst2","1"),new SugarParameter("@Const3","a")
|
||||||
|
}, "Replace error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Substring()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Substring("aaaa", 0, 2) == "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1",0) , new SugarParameter("@MethodConst2",2),new SugarParameter("@Const3","a")
|
||||||
|
}, "Substring error");
|
||||||
|
}
|
||||||
|
private void ExtendSubstring()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it =>"aaaa".Substring(0, 2)== "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","aaaa"), new SugarParameter("@MethodConst1",0) , new SugarParameter("@MethodConst2",2),new SugarParameter("@Const3","a")
|
||||||
|
}, "Substring error");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ToBool()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToBool("true") == true;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS BIT) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","true"),new SugarParameter("@Const1",(bool)true)
|
||||||
|
}, "ToBool error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToDouble()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDouble("2") == 2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS FLOAT) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","2"),new SugarParameter("@Const1",(Double)2)
|
||||||
|
}, "ToDouble error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToGuid()
|
||||||
|
{
|
||||||
|
var x2 = Guid.NewGuid();
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS UNIQUEIDENTIFIER) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","A94027A3-476E-478D-8228-F4054394B874"),new SugarParameter("@Const1",x2)
|
||||||
|
}, "ToGuid error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToDecimal()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDecimal("22") == 1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS MONEY) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","22"),new SugarParameter("@Const1",(decimal)1)
|
||||||
|
}, "ToDecimal error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Tostring()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToString("2015-1-1") == "a";
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS NVARCHAR(MAX)) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1","a")
|
||||||
|
}, "Tostring error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToDate()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDate("2015-1-1") == x2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
|
||||||
|
}, "ToDate error");
|
||||||
|
}
|
||||||
|
private void ExtendDate()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => Convert.ToDateTime("2015-1-1") == x2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
|
||||||
|
}, "ExtendDate error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToInt64()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt64("3") == 1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS BIGINT) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",(Int64)1)
|
||||||
|
}, "ToInt64 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToInt32()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt32("3") == 1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(CAST(@MethodConst0 AS INT) = @Const1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",1)
|
||||||
|
}, "ToInt32 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DateValue()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ((@MethodConst1(@MethodConst0)) = @Const2 ) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",DateType.Year),new SugarParameter("@Const2",1)
|
||||||
|
}, "DateValue error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartsWith()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.StartsWith(it.Name, "a");
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] like @MethodConst0+'%') ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "StartsWith error");
|
||||||
|
}
|
||||||
|
private void EndsWith()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.EndsWith(it.Name, "a");
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] like '%'+@MethodConst0) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "EndsWith");
|
||||||
|
}
|
||||||
|
private void Between()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Between(it.Name, 1, 2);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] BETWEEN @MethodConst0 AND @MethodConst1) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",1),new SugarParameter("@MethodConst1",2),
|
||||||
|
}, "Between error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DateAddByType()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 11, DateType.Millisecond) == x2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "((DATEADD(@MethodConst2,@MethodConst1,@MethodConst0)) = @Const3 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2),
|
||||||
|
new SugarParameter("@MethodConst2",DateType.Millisecond)
|
||||||
|
}, "DateAddByType error");
|
||||||
|
}
|
||||||
|
private void DateAddDay()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 1) == x2;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "((DATEADD(day,@MethodConst1,@MethodConst0)) = @Const2 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",1),new SugarParameter("@Const2",x2)
|
||||||
|
}, "DateIsSameByType error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DateIsSameByType()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2, DateType.Millisecond);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " (DATEDIFF(@MethodConst2,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2),
|
||||||
|
new SugarParameter("@MethodConst2",DateType.Millisecond)
|
||||||
|
}, "DateIsSameByType error");
|
||||||
|
}
|
||||||
|
private void DateIsSameByDay()
|
||||||
|
{
|
||||||
|
var x2 = DateTime.Now;
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(DATEDIFF(day,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
|
||||||
|
}, "DateIsSameDay error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Equals()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, "a");
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] = @MethodConst0) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "Equals1 error");
|
||||||
|
|
||||||
|
|
||||||
|
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", it.Name);
|
||||||
|
SqlServerExpressionContext expContext2 = new SqlServerExpressionContext();
|
||||||
|
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
|
||||||
|
var value2 = expContext2.Result.GetString();
|
||||||
|
var pars2 = expContext2.Parameters;
|
||||||
|
base.Check(value2, pars2, " (@MethodConst0 = [Name]) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "Equals2 error");
|
||||||
|
}
|
||||||
|
private void Equals_2()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, it.Name);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] = [Name]) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "Equals1 error");
|
||||||
|
|
||||||
|
|
||||||
|
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", "a2");
|
||||||
|
SqlServerExpressionContext expContext2 = new SqlServerExpressionContext();
|
||||||
|
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
|
||||||
|
var value2 = expContext2.Result.GetString();
|
||||||
|
var pars2 = expContext2.Parameters;
|
||||||
|
base.Check(value2, pars2, " (@MethodConst0 = @MethodConst1) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a"),new SugarParameter("@MethodConst1","a2")
|
||||||
|
}, "Equals2 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Contains()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, "a");
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "Contains error");
|
||||||
|
}
|
||||||
|
private void Contains2(string name="a")
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, name);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ([Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","a")
|
||||||
|
}, "Contains2 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExtendContainsArray() {
|
||||||
|
var array = new string[] { "1", "2" }.ToList();
|
||||||
|
Expression<Func<Student, bool>> exp = it => array.Contains(it.Name);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, null, " ([Name] IN ('1','2')) ", null, "Contains2 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContainsArray()
|
||||||
|
{
|
||||||
|
string[] array = new string[] { "1", "2" };
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.ContainsArray(array, it.Name);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, null, " ([Name] IN ('1','2')) ", null, "Contains2 error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Trim()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.Trim(" a") == it.Name;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = [Name] )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0"," a")
|
||||||
|
}, "Trim error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToUpper()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToUpper(it.Id);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( @Const0 = (UPPER([Id])) )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Const0","a")
|
||||||
|
}, "ToUpper error");
|
||||||
|
}
|
||||||
|
private void ToLower()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToLower(it.Id);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( @Const0 = (LOWER([Id])) )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Const0","a")
|
||||||
|
}, "ToLower error");
|
||||||
|
}
|
||||||
|
|
||||||
|
#region StringIsNullOrEmpty
|
||||||
|
private void StringIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id > 2 || SqlFunc.IsNullOrEmpty(it.Id); ;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( [Id] > @Id0 ) OR ( [Id]='' OR [Id] IS NULL ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",2)
|
||||||
|
}, "StringIsNullOrEmpty error");
|
||||||
|
}
|
||||||
|
private void StringIsNullOrEmpty2()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(true); ;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst1",true),
|
||||||
|
new SugarParameter("@Id0",2)
|
||||||
|
}, "StringIsNullOrEmpty2 error");
|
||||||
|
}
|
||||||
|
private void StringIsNullOrEmpty3()
|
||||||
|
{
|
||||||
|
int a = 1;
|
||||||
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(a); ;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst1",1),
|
||||||
|
new SugarParameter("@Id0",2)
|
||||||
|
}, "StringIsNullOrEmpty3 error");
|
||||||
|
}
|
||||||
|
private void StringIsNullOrEmpty4()
|
||||||
|
{
|
||||||
|
WhereConst.name = "xx";
|
||||||
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(WhereConst.name); ;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst1","xx"),
|
||||||
|
new SugarParameter("@Id0",2)
|
||||||
|
}, "StringIsNullOrEmpty4 error");
|
||||||
|
}
|
||||||
|
private void StringIsNullOrEmpty5()
|
||||||
|
{
|
||||||
|
WhereConst.name = "xx";
|
||||||
|
Expression<Func<Student, bool>> exp = it => !SqlFunc.IsNullOrEmpty(WhereConst.name); ;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "NOT( @MethodConst0='' OR @MethodConst0 IS NULL )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@MethodConst0","xx")
|
||||||
|
}, "StringIsNullOrEmpty5 error");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void HasValue()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.HasValue(it.Name);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Name]<>'' AND [Name] IS NOT NULL )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}, "HasValue error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HasNumber()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.HasNumber(it.Id);
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Id]>0 AND [Id] IS NOT NULL )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}, "HasNumber error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void IIF()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( CASE WHEN ( [Id] = @Id0 ) THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@MethodConst1",1),
|
||||||
|
new SugarParameter("@MethodConst2",2),
|
||||||
|
new SugarParameter("@Const3",1)
|
||||||
|
}, "IIF error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void IIF2()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name,"a"), 1, 2)==1;
|
||||||
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( CASE WHEN ([Name] like '%'+@MethodConst0+'%') THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
new SugarParameter("@MethodConst0","a"),
|
||||||
|
new SugarParameter("@MethodConst1",1),
|
||||||
|
new SugarParameter("@MethodConst2",2),
|
||||||
|
new SugarParameter("@Const3",1)
|
||||||
|
}, "IIF2 error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
99
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Select.cs
Normal file
99
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Select.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Select : UnitTestBase
|
||||||
|
{
|
||||||
|
private Select() { }
|
||||||
|
public Select(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
single();
|
||||||
|
Multiple();
|
||||||
|
singleDynamic();
|
||||||
|
MultipleDynamic();
|
||||||
|
}
|
||||||
|
base.End("Select Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Multiple()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, School, object>> exp = (it, school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id, TestId = it.Id + 1 };
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
selectorValue,
|
||||||
|
pars,
|
||||||
|
@" @constant1 AS Name , it.Id AS Id , school.Id AS SchoolId , ( it.Id + 1 ) AS TestId ",
|
||||||
|
new List<SugarParameter>(){
|
||||||
|
new SugarParameter("@constant1","a")},
|
||||||
|
"Select.Multiple Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MultipleDynamic()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
selectorValue,
|
||||||
|
pars,
|
||||||
|
@" @constant1 AS Name , ( it.Id / 2 ) AS Id , school.Id AS SchoolId ",
|
||||||
|
new List<SugarParameter>(){
|
||||||
|
new SugarParameter("@constant1","a")},
|
||||||
|
"Select.MultipleDynamic Error");
|
||||||
|
}
|
||||||
|
private void single()
|
||||||
|
{
|
||||||
|
int p = 1;
|
||||||
|
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p,TestId=it.Id+1 };
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
selectorValue,
|
||||||
|
pars,
|
||||||
|
@" @constant1 AS Name , Id AS Id , @constant3 AS SchoolId , ( Id + 1 ) AS TestId ",
|
||||||
|
new List<SugarParameter>(){
|
||||||
|
new SugarParameter("@constant1","a"),
|
||||||
|
new SugarParameter("@constant3",1)},
|
||||||
|
"Select.single Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void singleDynamic()
|
||||||
|
{
|
||||||
|
string a = "a";
|
||||||
|
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a,p=it.Id*1 };
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
selectorValue,
|
||||||
|
pars,
|
||||||
|
@" Id AS x , @constant2 AS shoolid , @constant3 AS name , ( Id * 1 ) AS p ",
|
||||||
|
new List<SugarParameter>(){
|
||||||
|
new SugarParameter("@constant2",1),
|
||||||
|
new SugarParameter("@constant3","a")},
|
||||||
|
"Select.single Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
258
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Where.cs
Normal file
258
Src/Asp.Net/MySqlTest/UnitTest/ExpressionTest/Where.cs
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Where : UnitTestBase
|
||||||
|
{
|
||||||
|
private Where() { }
|
||||||
|
public Where(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
whereSingle1();
|
||||||
|
whereSingle2();
|
||||||
|
whereSingle3();
|
||||||
|
whereSingle4();
|
||||||
|
whereSingle5();
|
||||||
|
whereSingle6();
|
||||||
|
whereSingle7(new Student() { Id = 1 });
|
||||||
|
whereSingle8(new Student() { Id = 1 });
|
||||||
|
whereSingle9(new Student() { Id = 1 });
|
||||||
|
whereSingle10();
|
||||||
|
whereSingle11();
|
||||||
|
whereSingle12();
|
||||||
|
whereSingle13();
|
||||||
|
whereSingle14();
|
||||||
|
WhereMultiple1();
|
||||||
|
WhereMultiple2();
|
||||||
|
|
||||||
|
}
|
||||||
|
base.End("Where Test");
|
||||||
|
}
|
||||||
|
private void WhereMultiple1()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id > 1;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [it].[Id] > @Id0 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1)
|
||||||
|
}, "WhereMultiple1");
|
||||||
|
}
|
||||||
|
private void WhereMultiple2()
|
||||||
|
{
|
||||||
|
string name = "a";
|
||||||
|
WhereConst.name = "a1";
|
||||||
|
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name || it.Id == 1) || it.Name == WhereConst.name;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " (((( [it].[Id] > @Id0 ) AND ( [it].[Name] <> @Name1 )) OR ( [it].[Id] = @Id2 )) OR ( [it].[Name] = @Name3 ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Name1","a"),
|
||||||
|
new SugarParameter("@Id2",1),
|
||||||
|
new SugarParameter("@Name3","a1")
|
||||||
|
}, "WhereMultiple2");
|
||||||
|
}
|
||||||
|
private void whereSingle1()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id > 1;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Id] > @Id0 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1)
|
||||||
|
}, "whereSingle1");
|
||||||
|
}
|
||||||
|
private void whereSingle2()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => 1 > it.Id;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( @Id0 > [Id] )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1)
|
||||||
|
}, "whereSingle2");
|
||||||
|
}
|
||||||
|
private void whereSingle3()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id > 1 || it.Name == "a";
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " (( [Id] > @Id0 ) OR ( [Name] = @Name1 ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Name1","a")
|
||||||
|
}, "whereSingle3");
|
||||||
|
}
|
||||||
|
private void whereSingle4()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != "a") || it.Name == "a1";
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Name] = @Name2 )) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Name1","a"),
|
||||||
|
new SugarParameter("@Name2","a1")
|
||||||
|
}, "whereSingle4");
|
||||||
|
}
|
||||||
|
private void whereSingle5()
|
||||||
|
{
|
||||||
|
string name = "a";
|
||||||
|
WhereConst.name = "a1";
|
||||||
|
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name) || it.Name == WhereConst.name;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " ((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Name] = @Name2 )) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Name1","a"),
|
||||||
|
new SugarParameter("@Name2","a1")
|
||||||
|
}, "whereSingle5");
|
||||||
|
}
|
||||||
|
private void whereSingle6()
|
||||||
|
{
|
||||||
|
string name = "a";
|
||||||
|
WhereConst.name = "a1";
|
||||||
|
Expression<Func<Student, bool>> exp = it => (it.Id > 1 && it.Name != name||it.Id==1) || it.Name == WhereConst.name;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, " (((( [Id] > @Id0 ) AND ( [Name] <> @Name1 )) OR ( [Id] = @Id2 )) OR ( [Name] = @Name3 ))", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Name1","a"),
|
||||||
|
new SugarParameter("@Id2",1),
|
||||||
|
new SugarParameter("@Name3","a1")
|
||||||
|
}, "whereSingle6");
|
||||||
|
}
|
||||||
|
private void whereSingle7(Student st)
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Id > st.Id;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Id] > @Id0 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1)
|
||||||
|
}, "whereSingle7");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whereSingle8(Student st)
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Name == null;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Name] IS NULL )", new List<SugarParameter>() {
|
||||||
|
|
||||||
|
}, "whereSingle8");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whereSingle9(Student st)
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Name == st.Name;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Name] = @Name0 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
new SugarParameter("@Name0",null)
|
||||||
|
}, "whereSingle9");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void whereSingle10()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => true;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( 1 = 1 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}, "whereSingle10");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void whereSingle11()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => !true;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( 1 = 2 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}, "whereSingle11");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whereSingle12()
|
||||||
|
{
|
||||||
|
Expression<Func<DataTestInfo2, bool>> exp = it => it.Bool1==true;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Bool1] = @Bool10 )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
new SugarParameter("@Bool10",true)
|
||||||
|
}, "whereSingle12");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whereSingle13()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it => it.Name!=null;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "( [Name] IS NOT NULL )", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}, "whereSingle13");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void whereSingle14()
|
||||||
|
{
|
||||||
|
Expression<Func<Student, bool>> exp = it =>true&& it.Name != null;
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||||
|
var value = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(value, pars, "(( 1 = 1 ) AND( [Name] IS NOT NULL ))", new List<SugarParameter>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}, "whereSingle14");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WhereConst
|
||||||
|
{
|
||||||
|
public static string name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
127
Src/Asp.Net/MySqlTest/UnitTest/Insert.cs
Normal file
127
Src/Asp.Net/MySqlTest/UnitTest/Insert.cs
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
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 : UnitTestBase
|
||||||
|
{
|
||||||
|
private Insert() { }
|
||||||
|
public Insert(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var insertObj = new Student() { Name = "jack", CreateTime = Convert.ToDateTime("2010-1-1"), SchoolId=0 };
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
//db.MappingColumns.Add("id","dbid", "Student");
|
||||||
|
|
||||||
|
var t1 = db.Insertable(insertObj).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent]
|
||||||
|
([SchoolId],[Name],[CreateTime])
|
||||||
|
VALUES
|
||||||
|
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
|
new SugarParameter("@Name","jack")
|
||||||
|
}, t1.Key, t1.Value, "Insert t1 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//Insert reutrn Command Count
|
||||||
|
var t2 = db.Insertable(insertObj).ExecuteCommand();
|
||||||
|
|
||||||
|
db.IgnoreColumns = null;
|
||||||
|
//Only insert Name
|
||||||
|
var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent]
|
||||||
|
([Name])
|
||||||
|
VALUES
|
||||||
|
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Name","jack")
|
||||||
|
}, t3.Key, t3.Value, "Insert t3 error");
|
||||||
|
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t4 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent]
|
||||||
|
([SchoolId],[CreateTime])
|
||||||
|
VALUES
|
||||||
|
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
|
}, t4.Key, t4.Value, "Insert t4 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||||
|
([SchoolId],[CreateTime])
|
||||||
|
VALUES
|
||||||
|
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
|
}, t5.Key, t5.Value, "Insert t5 error"
|
||||||
|
);
|
||||||
|
//Use Lock
|
||||||
|
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||||
|
([SchoolId],[Name],[CreateTime])
|
||||||
|
VALUES
|
||||||
|
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
|
new SugarParameter("@Name","jack")
|
||||||
|
}, t6.Key, t6.Value, "Insert t6 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
var insertObj2 = new Student() { Name = null,SchoolId=0, CreateTime = Convert.ToDateTime("2010-1-1") };
|
||||||
|
var t8 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ToSql();
|
||||||
|
base.Check(@"INSERT INTO [STudent]
|
||||||
|
([ID],[SchoolId],[CreateTime])
|
||||||
|
VALUES
|
||||||
|
(@ID,@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId", 0),
|
||||||
|
new SugarParameter("@ID", 0),
|
||||||
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1"))
|
||||||
|
},
|
||||||
|
t8.Key,
|
||||||
|
t8.Value,
|
||||||
|
"Insert t8 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
db.IgnoreColumns = new IgnoreComumnList();
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
|
||||||
|
//Insert List<T>
|
||||||
|
var insertObjs = new List<Student>();
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
insertObjs.Add(new Student() { Name = "name" + i });
|
||||||
|
}
|
||||||
|
var s9 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).With(SqlWith.UpdLock).ToSql();
|
||||||
|
|
||||||
|
insertObj.Name = null;
|
||||||
|
var t10 = db.Insertable(insertObj).ExecuteCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
Src/Asp.Net/MySqlTest/UnitTest/Mapping .cs
Normal file
46
Src/Asp.Net/MySqlTest/UnitTest/Mapping .cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
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 Mapping:UnitTestBase
|
||||||
|
{
|
||||||
|
private Mapping() { }
|
||||||
|
public Mapping(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init() {
|
||||||
|
|
||||||
|
var db = GetInstance();
|
||||||
|
var t1= db.Queryable<Student>().Where(it=>it.Id==1).ToSql();
|
||||||
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] = @Id0 ) ", null, t1.Key, null,"Mapping t1 error");
|
||||||
|
|
||||||
|
db.MappingColumns.Add("Id", "id", "School");
|
||||||
|
var t2 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
})
|
||||||
|
.Where(st => st.Id == 1)
|
||||||
|
.Where((st,sc) => sc.Id == 1)
|
||||||
|
.Where((st,sc) => sc.Id == st.Id)
|
||||||
|
.GroupBy(st => st.Id)
|
||||||
|
.GroupBy((st,sc) => sc.Id).OrderBy(st => st.Id,OrderByType.Asc)
|
||||||
|
.Select((st,sc)=> new { stid=st.Id,scid=sc.Id}).ToSql();
|
||||||
|
base.Check(@"SELECT [st].[ID] AS [stid] , [sc].[id] AS [scid] FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[id] ) WHERE ( [st].[ID] = @Id0 ) AND ( [sc].[id] = @Id1 ) AND ( [sc].[id] = [st].[ID] )GROUP BY [st].[ID],[sc].[id]ORDER BY [st].[ID] ASC ",
|
||||||
|
null, t2.Key, null, " Mapping t2 error");
|
||||||
|
var x2 = GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() {InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
83
Src/Asp.Net/MySqlTest/UnitTest/Query/JoinQuery.cs
Normal file
83
Src/Asp.Net/MySqlTest/UnitTest/Query/JoinQuery.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using OrmTest.Models;
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class JoinQuery : UnitTestBase
|
||||||
|
{
|
||||||
|
private JoinQuery() { }
|
||||||
|
public JoinQuery(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
Q1();
|
||||||
|
Q2();
|
||||||
|
Q3();
|
||||||
|
}
|
||||||
|
base.End("Method Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Q3()
|
||||||
|
{
|
||||||
|
using (var db = GetInstance())
|
||||||
|
{
|
||||||
|
var join3 = db.Queryable("Student", "st")
|
||||||
|
.AddJoinInfo("School", "sh", "sh.id=st.schoolid")
|
||||||
|
.Where("st.id>@id")
|
||||||
|
.AddParameters(new { id = 1 })
|
||||||
|
.Select("st.*").ToSql();
|
||||||
|
string sql = @"SELECT st.* FROM [Student] st Left JOIN School sh ON sh.id=st.schoolid WHERE st.id>@id ";
|
||||||
|
base.Check(sql,new List<SugarParameter>() {new SugarParameter("@id",1)}, join3.Key, join3.Value, "join 3 Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Q1()
|
||||||
|
{
|
||||||
|
using (var db = GetInstance())
|
||||||
|
{
|
||||||
|
var join1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
}).Where(st => st.Id > 0).Select<Student>("*").ToSql();
|
||||||
|
base.Check(@"SELECT * FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",0)
|
||||||
|
}, join1.Key, join1.Value, "join 1 Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Q2()
|
||||||
|
{
|
||||||
|
using (var db = GetInstance())
|
||||||
|
{
|
||||||
|
var join2 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id
|
||||||
|
}).Where(st => st.Id > 2).Select<Student>("*").ToSql();
|
||||||
|
base.Check(@"SELECT * FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",2)
|
||||||
|
}, join2.Key, join2.Value, "join 2 Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql });
|
||||||
|
db.Ado.IsEnableLogEvent = true;
|
||||||
|
db.Ado.LogEventStarting = (sql, pars) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql + " " + pars);
|
||||||
|
};
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
Src/Asp.Net/MySqlTest/UnitTest/Query/SelectQuery.cs
Normal file
94
Src/Asp.Net/MySqlTest/UnitTest/Query/SelectQuery.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using OrmTest.Models;
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class SelectQuery : UnitTestBase
|
||||||
|
{
|
||||||
|
private SelectQuery() { }
|
||||||
|
public SelectQuery(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
Q2();
|
||||||
|
}
|
||||||
|
base.End("Method Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Q2()
|
||||||
|
{
|
||||||
|
using (var db = GetInstance())
|
||||||
|
{
|
||||||
|
//db.Database.IsEnableLogEvent = true;
|
||||||
|
db.Ado.LogEventStarting = (sql, pars) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql + " " + pars);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#region dr ot entity
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
var s1 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Name = it.Name, Student = it }).ToList();
|
||||||
|
var s2 = db.Queryable<Student>().Select(it => new { id = it.Id, w = new { x = it } }).ToList();
|
||||||
|
var s3 = db.Queryable<Student>().Select(it => new { newid = it.Id }).ToList();
|
||||||
|
var s4 = db.Queryable<Student>().Select(it => new { newid = it.Id, obj = it }).ToList();
|
||||||
|
var s5 = db.Queryable<Student>().Select(it => new ViewModelStudent2 { Student = it, Name = it.Name }).ToList();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region sql and parameters validate
|
||||||
|
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
JoinType.Inner,st.Id==sc.Id
|
||||||
|
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.AggregateAvg(st.Id) }).ToSql();
|
||||||
|
base.Check("SELECT AVG([st].[ID]) AS [avgId] FROM [STudent] st Inner JOIN School sc ON ( [st].[ID] = [sc].[Id] ) GROUP BY [st].[ID] HAVING (AVG([st].[ID]) = @Const0 ) ",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Const0",1)
|
||||||
|
}
|
||||||
|
,
|
||||||
|
t1.Key, t1.Value, " select t1 Error");
|
||||||
|
|
||||||
|
|
||||||
|
var t2 = db.Queryable<School, School>((st, st2) => new object[] {
|
||||||
|
JoinType.Left,st.Id==st2.Id
|
||||||
|
})
|
||||||
|
.Where(st => st.Id > 0)
|
||||||
|
.Select((st, st2) => new { stid = st.Id, scId = st2.Id, xx = st }).ToSql();
|
||||||
|
|
||||||
|
base.Check("SELECT [st].[Id] AS [stid] , [st2].[Id] AS [scId] , [st].[Id] AS [School.Id] , [st].[Name] AS [School.Name] FROM [School] st Left JOIN School st2 ON ( [st].[Id] = [st2].[Id] ) WHERE ( [st].[Id] > @Id0 ) "
|
||||||
|
, new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",0)
|
||||||
|
}, t2.Key, t2.Value, "select t2 Error");
|
||||||
|
|
||||||
|
|
||||||
|
var t3 = db.Queryable<Student, School, School>((st, sc, sc2) => new object[] {
|
||||||
|
JoinType.Left,st.SchoolId==sc.Id,
|
||||||
|
JoinType.Left,sc2.Id==sc.Id
|
||||||
|
}).Where(st => st.Id > 0)
|
||||||
|
.Select<School>((st) => new School() { Id = st.Id }).ToSql();
|
||||||
|
base.Check("SELECT [st].[ID] AS [Id] FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) Left JOIN School sc2 ON ( [sc2].[Id] = [sc].[Id] ) WHERE ( [st].[ID] > @Id0 ) ",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",0)
|
||||||
|
}, t3.Key, t3.Value, "select t3 Error");
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
131
Src/Asp.Net/MySqlTest/UnitTest/Query/SingleQuery.cs
Normal file
131
Src/Asp.Net/MySqlTest/UnitTest/Query/SingleQuery.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using OrmTest.Models;
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class SingleQuery : UnitTestBase
|
||||||
|
{
|
||||||
|
private SingleQuery() { }
|
||||||
|
public SingleQuery(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
internal void Init()
|
||||||
|
{
|
||||||
|
base.Begin();
|
||||||
|
for (int i = 0; i < base.Count; i++)
|
||||||
|
{
|
||||||
|
Q2();
|
||||||
|
}
|
||||||
|
base.End("Method Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Q2()
|
||||||
|
{
|
||||||
|
using (var db = GetInstance())
|
||||||
|
{
|
||||||
|
var t1 = db.Queryable<Student>().ToSql();
|
||||||
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]", null, t1.Key, null, "single t1 Error");
|
||||||
|
|
||||||
|
var t2 = db.Queryable<Student>().With(SqlWith.NoLock).ToSql();
|
||||||
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK)", null, t2.Key, null, "single t2 Error");
|
||||||
|
|
||||||
|
var t3 = db.Queryable<Student>().OrderBy(it=>it.Id).ToSql();
|
||||||
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] ORDER BY [ID] ASC", null, t3.Key, null, "single t3 Error");
|
||||||
|
|
||||||
|
var t4 = db.Queryable<Student>().OrderBy(it => it.Id).Take(3).ToSql();
|
||||||
|
base.Check(@"WITH PageTable AS(
|
||||||
|
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||||
|
)
|
||||||
|
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 1 AND 3", null, t4.Key, null, "single t4 Error");
|
||||||
|
|
||||||
|
var t5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql();
|
||||||
|
base.Check(@"WITH PageTable AS(
|
||||||
|
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||||
|
)
|
||||||
|
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, t5.Key,null, "single t5 Error");
|
||||||
|
|
||||||
|
int pageIndex = 2;
|
||||||
|
int pageSize = 10;
|
||||||
|
var t6 = db.Queryable<Student>().OrderBy(it => it.Id,OrderByType.Desc).Skip((pageIndex-1)*pageSize).Take(pageSize).ToSql();
|
||||||
|
base.Check(@"WITH PageTable AS(
|
||||||
|
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||||
|
)
|
||||||
|
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", null, t6.Key, null, "single t6 Error");
|
||||||
|
|
||||||
|
|
||||||
|
int studentCount=db.Ado.GetInt("select count(1) from Student");
|
||||||
|
var countIsSuccess=db.Queryable<Student>().Count()== studentCount;
|
||||||
|
if (!countIsSuccess) {
|
||||||
|
throw new Exception(" single countIsSuccess Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
var t7 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToPageList(pageIndex,pageSize,ref studentCount);
|
||||||
|
countIsSuccess = studentCount == db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).Count();
|
||||||
|
if (!countIsSuccess)
|
||||||
|
{
|
||||||
|
throw new Exception("single t7 Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
int studentMin = db.Ado.GetInt("select min(id) from Student");
|
||||||
|
var minIsSuccess = db.Queryable<Student>().Min(it=>it.Id) == studentMin;
|
||||||
|
if (!minIsSuccess)
|
||||||
|
{
|
||||||
|
throw new Exception("single minIsSuccess Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
int studentMax = db.Ado.GetInt("select max(id) from Student");
|
||||||
|
var maxIsSuccess = db.Queryable<Student>().Max(it => it.Id) == studentMax;
|
||||||
|
if (!maxIsSuccess)
|
||||||
|
{
|
||||||
|
throw new Exception("single maxIsSuccess Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
int studentAvg = db.Ado.GetInt("select avg(id) from Student");
|
||||||
|
var avgIsSuccess = db.Queryable<Student>().Avg(it => it.Id) == studentAvg;
|
||||||
|
if (!maxIsSuccess)
|
||||||
|
{
|
||||||
|
throw new Exception(" single avgIsSuccess Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
int studentSum = db.Ado.GetInt("select sum(id) from Student");
|
||||||
|
var sumIsSuccess = db.Queryable<Student>().Sum(it => it.Id) == studentSum;
|
||||||
|
if (!sumIsSuccess)
|
||||||
|
{
|
||||||
|
throw new Exception("single sumIsSuccess Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
var t8 = db.Queryable<Student>()
|
||||||
|
.Where(it=>it.Id==1)
|
||||||
|
.WhereIF(true,it=> SqlFunc.Contains(it.Name,"a"))
|
||||||
|
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize ).With(SqlWith.NoLock).ToSql();
|
||||||
|
base.Check(@"WITH PageTable AS(
|
||||||
|
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK) WHERE ( [ID] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%')
|
||||||
|
)
|
||||||
|
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
|
||||||
|
}, t8.Key, t8.Value,"single t8 Error");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var t9 = db.Queryable<Student>()
|
||||||
|
.In(1)
|
||||||
|
.Select(it => new { it.Id, it.Name,x=it.Id }).ToSql();
|
||||||
|
base.Check("SELECT [ID] AS [Id] , [Name] AS [Name] , [ID] AS [x] FROM [STudent] WHERE [Id] IN (@InPara0) ", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@InPara0",1) },t9.Key,t9.Value, "single t9 error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
Src/Asp.Net/MySqlTest/UnitTest/Setting/Attribute.cs
Normal file
20
Src/Asp.Net/MySqlTest/UnitTest/Setting/Attribute.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Attribute : UnitTestBase
|
||||||
|
{
|
||||||
|
public Attribute(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
Src/Asp.Net/MySqlTest/UnitTest/Setting/AutoClose.cs
Normal file
32
Src/Asp.Net/MySqlTest/UnitTest/Setting/AutoClose.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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 AutoClose : UnitTestBase
|
||||||
|
{
|
||||||
|
public AutoClose(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
//IsAutoCloseConnection
|
||||||
|
for (int i = 0; i < this.Count; i++)
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var x = db.Queryable<Student>().ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
Src/Asp.Net/MySqlTest/UnitTest/Setting/MapColumn.cs
Normal file
18
Src/Asp.Net/MySqlTest/UnitTest/Setting/MapColumn.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class MapColumn : UnitTestBase
|
||||||
|
{
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
Src/Asp.Net/MySqlTest/UnitTest/Setting/MapTable.cs
Normal file
28
Src/Asp.Net/MySqlTest/UnitTest/Setting/MapTable.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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 MapTable : UnitTestBase
|
||||||
|
{
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
//IsAutoCloseConnection
|
||||||
|
for (int i = 0; i < 200; i++)
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var x = db.Queryable<Student>().ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
Src/Asp.Net/MySqlTest/UnitTest/UnitTestBase.cs
Normal file
49
Src/Asp.Net/MySqlTest/UnitTest/UnitTestBase.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using SqlSugar;
|
||||||
|
using System.Linq;
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class UnitTestBase
|
||||||
|
{
|
||||||
|
public int Count { get; set; }
|
||||||
|
private DateTime BeginTime { get; set; }
|
||||||
|
private DateTime EndTime { get; set; }
|
||||||
|
|
||||||
|
public void Begin()
|
||||||
|
{
|
||||||
|
this.BeginTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void End(string title)
|
||||||
|
{
|
||||||
|
this.EndTime = DateTime.Now;
|
||||||
|
Console.WriteLine(title + " \r\nCount: " + this.Count + "\r\nTime: " + (this.EndTime - this.BeginTime).TotalSeconds + " Seconds \r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Check(string value, List<SugarParameter> pars, string validValue, List<SugarParameter> validPars, string errorMessage)
|
||||||
|
{
|
||||||
|
if (value.Trim() != validValue.Trim())
|
||||||
|
{
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
if (pars != null && pars.Count > 0)
|
||||||
|
{
|
||||||
|
if (pars.Count != validPars.Count)
|
||||||
|
{
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var item in pars)
|
||||||
|
{
|
||||||
|
if (!validPars.Any(it => it.ParameterName.Equals(item.ParameterName) && it.Value.ObjToString().Equals(item.Value.ObjToString())))
|
||||||
|
{
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
135
Src/Asp.Net/MySqlTest/UnitTest/Update.cs
Normal file
135
Src/Asp.Net/MySqlTest/UnitTest/Update.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
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 Update : UnitTestBase
|
||||||
|
{
|
||||||
|
private Update() { }
|
||||||
|
public Update(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var updateObj = new Student() { Id = 1, Name = "jack",SchoolId=0, CreateTime = Convert.ToDateTime("2017-05-21 09:56:12.610") };
|
||||||
|
var updateObjs = new List<Student>() { updateObj,new Student() { Id=2,Name="sun",SchoolId=0 } }.ToArray();
|
||||||
|
db.IgnoreColumns.Add("TestId", "Student");
|
||||||
|
//db.MappingColumns.Add("id","dbid", "Student");
|
||||||
|
|
||||||
|
var t1 = db.Updateable(updateObj).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@Name", "jack")
|
||||||
|
}, t1.Key, t1.Value,"Update t1 error");
|
||||||
|
|
||||||
|
//update reutrn Command Count
|
||||||
|
var t2 = db.Updateable(updateObj).ExecuteCommand();
|
||||||
|
|
||||||
|
db.IgnoreColumns = null;
|
||||||
|
//Only update Name
|
||||||
|
var t3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name }).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
new SugarParameter("@Name", "jack")
|
||||||
|
}, t3.Key, t3.Value, "Update t3 error");
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@SchoolId", 0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
}, t4.Key, t4.Value, "Update t4 error");
|
||||||
|
|
||||||
|
//Ignore Name and TestId
|
||||||
|
var t5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||||
|
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@SchoolId", 0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
}, t5.Key, t5.Value, "Update t5 error");
|
||||||
|
|
||||||
|
|
||||||
|
//Use Lock
|
||||||
|
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||||
|
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@Name", "jack")
|
||||||
|
}, t6.Key, t6.Value, "Update t6 error");
|
||||||
|
|
||||||
|
|
||||||
|
// //update List<T>
|
||||||
|
// var t7 = db.Updateable(updateObjs).With(SqlWith.UpdLock).ToSql();
|
||||||
|
// base.Check(@"UPDATE S SET S.[SchoolId]=T.[SchoolId],S.[Name]=T.[Name],S.[CreateTime]=T.[CreateTime] FROM [STudent] S WITH(UPDLOCK) INNER JOIN (
|
||||||
|
|
||||||
|
// SELECT N'1' AS ID,N'0' AS SchoolId,N'jack' AS Name,'2017-05-21 09:56:12.610' AS CreateTime
|
||||||
|
//UNION ALL
|
||||||
|
// SELECT N'2' AS ID,N'0' AS SchoolId,N'sun' AS Name,NULL AS CreateTime
|
||||||
|
|
||||||
|
|
||||||
|
// ) T ON S.[Id]=T.[Id]
|
||||||
|
// ; ", null, t7.Key, null,"Update t7 error");
|
||||||
|
|
||||||
|
//Re Set Value
|
||||||
|
var t8 = db.Updateable(updateObj)
|
||||||
|
.ReSetValue(it=>it.Name==(it.Name+1)).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[SchoolId]=@SchoolId, [Name] =( [Name] + @Const0 ),[CreateTime]=@CreateTime WHERE [Id]=@Id",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@Const0", 1)
|
||||||
|
}, t8.Key, t8.Value, "Update t8 error"
|
||||||
|
);
|
||||||
|
|
||||||
|
//Where By Expression
|
||||||
|
var t9 = db.Updateable(updateObj)
|
||||||
|
.Where(it => it.Id==1).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE ( [ID] = @Id0 )",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@SchoolId",0),
|
||||||
|
new SugarParameter("@ID",1),
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||||
|
new SugarParameter("@Name", "jack") },t9.Key,t9.Value,"Upate t9 error"
|
||||||
|
);
|
||||||
|
updateObj.SchoolId = 18;
|
||||||
|
string name = "x";
|
||||||
|
var t10 = db.Updateable<Student>().UpdateColumns(it => new Student() { Name =name, SchoolId=updateObj.SchoolId }).Where(it=>it.Id==11).ToSql();
|
||||||
|
base.Check(@"UPDATE [STudent] SET
|
||||||
|
[SchoolId] = @Const0 , [Name] = @const3 WHERE ( [ID] = @Id1 )", new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@const3","x"),
|
||||||
|
new SugarParameter("@Const0",18),
|
||||||
|
new SugarParameter("@Id1",11)},
|
||||||
|
t10.Key,
|
||||||
|
t10.Value,
|
||||||
|
"Update 10 error"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSugar", "SqlSugar\SqlSug
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlServerTest", "SqlServerTest\SqlServerTest.csproj", "{CB591654-0476-40AA-8508-784CF32BE239}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlServerTest", "SqlServerTest\SqlServerTest.csproj", "{CB591654-0476-40AA-8508-784CF32BE239}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySqlTest", "MySqlTest\MySqlTest.csproj", "{B72FC095-9AFA-4375-AF14-402339BAF1DF}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -21,6 +23,10 @@ Global
|
|||||||
{CB591654-0476-40AA-8508-784CF32BE239}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CB591654-0476-40AA-8508-784CF32BE239}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{CB591654-0476-40AA-8508-784CF32BE239}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CB591654-0476-40AA-8508-784CF32BE239}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{CB591654-0476-40AA-8508-784CF32BE239}.Release|Any CPU.Build.0 = Release|Any CPU
|
{CB591654-0476-40AA-8508-784CF32BE239}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B72FC095-9AFA-4375-AF14-402339BAF1DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B72FC095-9AFA-4375-AF14-402339BAF1DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B72FC095-9AFA-4375-AF14-402339BAF1DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B72FC095-9AFA-4375-AF14-402339BAF1DF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class MySqlCodeFirst:CodeFirstProvider
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,18 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return new List<KeyValuePair<string, CSharpDataType>>()
|
return new List<KeyValuePair<string, CSharpDataType>>()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
|
||||||
|
|
||||||
|
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("enum",CSharpDataType.@string),
|
||||||
|
|
||||||
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
|
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
|
||||||
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
|
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
|
||||||
new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
||||||
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
|
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
|
||||||
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double),
|
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double),
|
||||||
@ -23,23 +30,23 @@ namespace SqlSugar
|
|||||||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
|
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
|
||||||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
|
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
|
||||||
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
|
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
|
||||||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
new KeyValuePair<string, CSharpDataType>("year",CSharpDataType.@int),
|
||||||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
|
|
||||||
|
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
|
||||||
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
|
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
|
||||||
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
|
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
|
||||||
new KeyValuePair<string, CSharpDataType>("year",CSharpDataType.@int),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("multipoint",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("multipoint",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("geometry",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("geometry",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("multilinestring",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("multilinestring",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("polygon",CSharpDataType.byteArray),
|
new KeyValuePair<string, CSharpDataType>("polygon",CSharpDataType.byteArray),
|
||||||
new KeyValuePair<string, CSharpDataType>("enum",CSharpDataType.@string),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class mySqlDbFirst : DbFirstProvider
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,179 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class MySqlDbMaintenance:DbMaintenanceProvider
|
||||||
|
{
|
||||||
|
#region DML
|
||||||
|
protected override string GetColumnInfosByTableNameSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string sql = @"SELECT
|
||||||
|
0 as TableId,
|
||||||
|
TABLE_NAME as TableName,
|
||||||
|
column_name AS DbColumnName,
|
||||||
|
left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1) AS DataType,
|
||||||
|
SUBSTRING(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)+1,LOCATE(')',COLUMN_TYPE)-LOCATE('(',COLUMN_TYPE)-1) AS Length,
|
||||||
|
column_default AS `DefaultValue`,
|
||||||
|
column_comment AS `ColumnDescription`,
|
||||||
|
CASE WHEN COLUMN_KEY = 'PRI'
|
||||||
|
THEN 1 ELSE 0 END AS `IsPrimaryKey`,
|
||||||
|
CASE WHEN is_nullable = 'YES'
|
||||||
|
THEN 1 ELSE 0 END AS `IsNullable`
|
||||||
|
FROM
|
||||||
|
Information_schema.columns where TABLE_NAME='{0}' ORDER BY TABLE_NAME";
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string GetTableInfoListSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables
|
||||||
|
where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='BASE TABLE'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string GetViewInfoListSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables
|
||||||
|
where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='VIEW'
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DDL
|
||||||
|
protected override string AddPrimaryKeySql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "ALTER TABLE {0} ADD CONSTRAINT {1} PRIMARY KEY({2})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string AddColumnToTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "ALTER TABLE {0} ADD {1} {2}{3} {4} {5} {6}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string AlterColumnToTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "ALTER TABLE {0} ALTER COLUMN {1} {2}{3} {4} {5} {6}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string BackupDataBaseSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return @"USE master;BACKUP DATABASE {0} TO disk = '{1}'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "CREATE TABLE {0}(\r\n{1})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableColumn
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "{0} {1}{2} {3} {4} {5}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string TruncateTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "TRUNCATE TABLE {0}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string BackupTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "SELECT TOP {0} * INTO {1} FROM {2}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string DropTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "DROP TABLE {0}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string DropColumnToTableSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "ALTER TABLE {0} DROP COLUMN {1}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string DropConstraintSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string RenameColumnSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "exec sp_rename '{0}.{1}','{2}','column';";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Check
|
||||||
|
protected override string CheckSystemTablePermissionsSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "select 1 from Information_schema.columns limit 0,1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Scattered
|
||||||
|
protected override string CreateTableNull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "NULL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableNotNull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "NOT NULL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTablePirmaryKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "PRIMARY KEY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableIdentity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "IDENTITY(1,1)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -3,10 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SqlSugar.Realization.MySql
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public partial class DbType
|
public partial class DbType
|
||||||
{
|
{
|
||||||
// public const string MySql = "MySql";
|
public const string MySql = "MySql";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
||||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||||
|
<Compile Include="Realization\MySql\CodeFirst\MySqlCodeFirst.cs" />
|
||||||
|
<Compile Include="Realization\MySql\DbFirst\MySqlDbFirst.cs" />
|
||||||
|
<Compile Include="Realization\MySql\DbMaintenance\MySqlDbMaintenance.cs" />
|
||||||
<Compile Include="SimpleClient.cs" />
|
<Compile Include="SimpleClient.cs" />
|
||||||
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
|
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
|
||||||
<Compile Include="Entities\ModelContext.cs" />
|
<Compile Include="Entities\ModelContext.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user