mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Merge branch 'master' of gitee.com:sunkaixuan/sqlsugar_orm_4-0
This commit is contained in:
@@ -8,8 +8,8 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest";
|
||||
public static string ConnectionString2 = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST";
|
||||
public static string ConnectionString3 = "server=.;uid=sa;pwd=sasa;database=sqlsugar4xtest";
|
||||
public static string ConnectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest";
|
||||
public static string ConnectionString2 = "server=.;uid=sa;pwd=@jhl85661501;database=SQLSUGAR4XTEST";
|
||||
public static string ConnectionString3 = "server=.;uid=sa;pwd=@jhl85661501;database=sqlsugar4xtest";
|
||||
}
|
||||
}
|
||||
|
@@ -194,6 +194,27 @@ namespace OrmTest.Demo
|
||||
db.Ado.RollbackTran();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//async tran
|
||||
var asyncResult = db.Ado.UseTranAsync(() =>
|
||||
{
|
||||
|
||||
var beginCount = db.Queryable<Student>().ToList();
|
||||
db.Ado.ExecuteCommand("delete student");
|
||||
var endCount = db.Queryable<Student>().Count();
|
||||
throw new Exception("error haha");
|
||||
});
|
||||
asyncResult.Wait();
|
||||
var asyncCount = db.Queryable<Student>().Count();
|
||||
|
||||
//async
|
||||
var asyncResult2 = db.Ado.UseTranAsync<List<Student>>(() =>
|
||||
{
|
||||
return db.Queryable<Student>().ToList();
|
||||
});
|
||||
asyncResult2.Wait();
|
||||
}
|
||||
private static void Group()
|
||||
{
|
||||
@@ -244,6 +265,8 @@ namespace OrmTest.Demo
|
||||
var db = GetInstance();
|
||||
var dbTime = db.GetDate();
|
||||
var getAll = db.Queryable<Student>().Select<object>("*").ToList();
|
||||
var getAll2 = db.Queryable<Student>().ToList();
|
||||
var getRandomList = db.Queryable<Student>().OrderBy(it => SqlFunc.GetRandom()).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();
|
||||
|
@@ -194,6 +194,17 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<DbResult<bool>> UseTranAsync(Action action)
|
||||
{
|
||||
Task<DbResult<bool>> result = new Task<DbResult<bool>>(() =>
|
||||
{
|
||||
return UseTran(action);
|
||||
});
|
||||
TaskStart(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public DbResult<T> UseTran<T>(Func<T> action)
|
||||
{
|
||||
var result = new DbResult<T>();
|
||||
@@ -214,6 +225,17 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action)
|
||||
{
|
||||
Task<DbResult<T>> result = new Task<DbResult<T>>(() =>
|
||||
{
|
||||
return UseTran(action);
|
||||
});
|
||||
TaskStart(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void UseStoredProcedure(Action action)
|
||||
{
|
||||
var oldCommandType = this.CommandType;
|
||||
@@ -624,6 +646,14 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
private void TaskStart<Type>(Task<Type> result)
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||
{
|
||||
Check.Exception(true, "IsShardSameThread=true can't be used async method");
|
||||
}
|
||||
result.Start();
|
||||
}
|
||||
private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
|
||||
{
|
||||
var result = this.ProcessingEventStartingSQL(sql, parameters);
|
||||
|
@@ -62,6 +62,10 @@ namespace SqlSugar
|
||||
IsAs = true;
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
||||
if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
|
||||
{
|
||||
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
|
||||
}
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
return this; ;
|
||||
}
|
||||
|
@@ -145,6 +145,10 @@ namespace SqlSugar
|
||||
IsAs = true;
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
||||
if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
|
||||
{
|
||||
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
|
||||
}
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
return this; ;
|
||||
}
|
||||
|
@@ -628,7 +628,7 @@ namespace SqlSugar
|
||||
}
|
||||
public ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
if (IsCache)
|
||||
if (isCache)
|
||||
{
|
||||
this.IsCache = true;
|
||||
this.CacheTime = cacheDurationInSeconds;
|
||||
@@ -1019,6 +1019,10 @@ namespace SqlSugar
|
||||
IsAs = true;
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
||||
if (this.Context.MappingTables.Any(it => it.EntityName == entityName))
|
||||
{
|
||||
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
|
||||
}
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
this.QueryableMappingTableList = this.Context.MappingTables;
|
||||
return this;
|
||||
@@ -1212,6 +1216,7 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString;
|
||||
asyncQueryableBuilder.GroupByValue = this.QueryBuilder.GroupByValue;
|
||||
asyncQueryableBuilder.OrderByValue = this.QueryBuilder.OrderByValue;
|
||||
asyncQueryableBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter;
|
||||
return asyncQueryable;
|
||||
}
|
||||
#endregion
|
||||
|
@@ -64,6 +64,9 @@ namespace SqlSugar
|
||||
IsAs = true;
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
||||
if (this.Context.MappingTables.Any(it => it.EntityName == entityName)) {
|
||||
this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName);
|
||||
}
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
return this; ;
|
||||
}
|
||||
|
@@ -325,6 +325,11 @@ namespace SqlSugar
|
||||
return "GETDATE()";
|
||||
}
|
||||
|
||||
public virtual string GetRandom()
|
||||
{
|
||||
return "NEWID()";
|
||||
}
|
||||
|
||||
public virtual string CaseWhen(List<KeyValuePair<string, string>> sqls)
|
||||
{
|
||||
StringBuilder reslut = new StringBuilder();
|
||||
|
@@ -59,5 +59,6 @@ namespace SqlSugar
|
||||
string Pack(string sql);
|
||||
string Null();
|
||||
string GetDate();
|
||||
string GetRandom();
|
||||
}
|
||||
}
|
||||
|
@@ -110,6 +110,7 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static string GetRandom() { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
/// <summary>
|
||||
/// Subquery
|
||||
/// </summary>
|
||||
|
@@ -504,6 +504,8 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle);
|
||||
case "GetDate":
|
||||
return this.Context.DbMehtods.GetDate();
|
||||
case "GetRandom":
|
||||
return this.Context.DbMehtods.GetRandom();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -86,6 +86,9 @@ namespace SqlSugar
|
||||
|
||||
DbResult<bool> UseTran(Action action);
|
||||
DbResult<T> UseTran<T>(Func<T> action);
|
||||
Task<DbResult<bool>> UseTranAsync(Action action);
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action);
|
||||
|
||||
void UseStoredProcedure(Action action);
|
||||
T UseStoredProcedure<T>(Func<T> action);
|
||||
IAdo UseStoredProcedure();
|
||||
|
@@ -133,5 +133,10 @@ namespace SqlSugar
|
||||
{
|
||||
return "NOW()";
|
||||
}
|
||||
|
||||
public override string GetRandom()
|
||||
{
|
||||
return "rand()";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -180,5 +180,10 @@ namespace SqlSugar
|
||||
{
|
||||
return "sysdate";
|
||||
}
|
||||
|
||||
public override string GetRandom()
|
||||
{
|
||||
return "dbms_random.value";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -208,5 +208,10 @@ namespace SqlSugar
|
||||
{
|
||||
return "DATETIME('now')";
|
||||
}
|
||||
|
||||
public override string GetRandom()
|
||||
{
|
||||
return "RANDOM()";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user