mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-14 10:15:03 +08:00
Update Core
This commit is contained in:
@@ -185,7 +185,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Use
|
||||
public DbResult<bool> UseTran(Action action)
|
||||
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack=null)
|
||||
{
|
||||
var result = new DbResult<bool>();
|
||||
try
|
||||
@@ -202,21 +202,25 @@ namespace SqlSugar
|
||||
result.ErrorMessage = ex.Message;
|
||||
result.IsSuccess = false;
|
||||
this.RollbackTran();
|
||||
if (errorCallBack != null)
|
||||
{
|
||||
errorCallBack(ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<DbResult<bool>> UseTranAsync(Action action)
|
||||
public Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null)
|
||||
{
|
||||
Task<DbResult<bool>> result = new Task<DbResult<bool>>(() =>
|
||||
{
|
||||
return UseTran(action);
|
||||
return UseTran(action,errorCallBack);
|
||||
});
|
||||
TaskStart(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public DbResult<T> UseTran<T>(Func<T> action)
|
||||
public DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
||||
{
|
||||
var result = new DbResult<T>();
|
||||
try
|
||||
@@ -233,15 +237,19 @@ namespace SqlSugar
|
||||
result.ErrorMessage = ex.Message;
|
||||
result.IsSuccess = false;
|
||||
this.RollbackTran();
|
||||
if (errorCallBack != null)
|
||||
{
|
||||
errorCallBack(ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action)
|
||||
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
||||
{
|
||||
Task<DbResult<T>> result = new Task<DbResult<T>>(() =>
|
||||
{
|
||||
return UseTran(action);
|
||||
return UseTran(action,errorCallBack);
|
||||
});
|
||||
TaskStart(result);
|
||||
return result;
|
||||
@@ -463,6 +471,10 @@ namespace SqlSugar
|
||||
{
|
||||
return GetInt(sql, this.GetParameters(parameters));
|
||||
}
|
||||
public virtual long GetLong(string sql, object parameters)
|
||||
{
|
||||
return Convert.ToInt64(GetScalar(sql, GetParameters(parameters)));
|
||||
}
|
||||
public virtual int GetInt(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
return GetScalar(sql, parameters).ObjToInt();
|
||||
|
@@ -198,6 +198,10 @@ namespace SqlSugar
|
||||
{
|
||||
method = isNullableType ? getConvertInt32 : getInt32;
|
||||
}
|
||||
else if (bindPropertyType == UtilConstants.ByteType)
|
||||
{
|
||||
method = isNullableType ? getConvertByte : getByte;
|
||||
}
|
||||
else if (bindPropertyType == UtilConstants.StringType)
|
||||
{
|
||||
method = getString;
|
||||
|
@@ -40,6 +40,10 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (InsertBuilder.DbColumnInfoList.HasValue())
|
||||
{
|
||||
var pks = GetPrimaryKeys();
|
||||
@@ -76,6 +80,10 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual int ExecuteReturnIdentity()
|
||||
{
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
@@ -88,6 +96,10 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual long ExecuteReturnBigIdentity()
|
||||
{
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
@@ -353,6 +365,10 @@ namespace SqlSugar
|
||||
}
|
||||
private void SetInsertItemByEntity(int i, T item, List<DbColumnInfo> insertItem)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var column in EntityInfo.Columns)
|
||||
{
|
||||
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
|
||||
|
@@ -554,6 +554,10 @@ namespace SqlSugar
|
||||
result.Context = this.Context;
|
||||
result.SqlBuilder = this.SqlBuilder;
|
||||
QueryBuilder.SelectValue = selectValue;
|
||||
if (this.IsAs)
|
||||
{
|
||||
((QueryableProvider<TResult>)result).IsAs = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Select(string selectValue)
|
||||
|
@@ -407,6 +407,10 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expression is LambdaExpression && (expression as LambdaExpression).Body is MethodCallExpression&&this.Context.CurrentConnectionConfig.DbType==DbType.SqlServer&&this.OrderByValue.HasValue())
|
||||
{
|
||||
result = result + " AS columnName";
|
||||
}
|
||||
this.SelectCacheKey = result;
|
||||
return result;
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -188,10 +189,10 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? null : " AND ");
|
||||
whereString += item;
|
||||
whereString += Regex.Replace(item,"\\"+this.Builder.SqlTranslationLeft,"T."+ this.Builder.SqlTranslationLeft);
|
||||
}
|
||||
}
|
||||
else if (PrimaryKeys.HasValue())
|
||||
if (PrimaryKeys.HasValue())
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
|
@@ -210,7 +210,7 @@ namespace SqlSugar
|
||||
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
||||
Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString());
|
||||
Check.Exception(ExpressionTool.IsConstExpression(binaryExp.Left as MemberExpression), "No support {0}", columns.ToString());
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace("))", ") )").Replace("((", "( (").Trim().TrimStart('(').TrimEnd(')');
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace(")", " )").Replace("(", "( ").Trim().TrimStart('(').TrimEnd(')');
|
||||
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
||||
|
@@ -32,10 +32,18 @@ namespace SqlSugar
|
||||
{
|
||||
ResolveValueBool(parameter, baseParameter, expression, isLeft, isSingle);
|
||||
}
|
||||
else if (isValue && expression.Expression != null && expression.Expression is MethodCallExpression)
|
||||
{
|
||||
ResolveCallValue(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
|
||||
}
|
||||
else if (isValue)
|
||||
{
|
||||
ResolveValue(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
|
||||
}
|
||||
else if (expression.Expression != null && expression.Expression.Type == UtilConstants.DateType && expression is MemberExpression && expression.Expression is MethodCallExpression)
|
||||
{
|
||||
ResolveDateDateByCall(parameter, isLeft, expression);
|
||||
}
|
||||
else if (isDateDate)
|
||||
{
|
||||
ResolveDateDate(parameter, isLeft, expression);
|
||||
@@ -54,6 +62,7 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Resolve default
|
||||
private void ResolveDefault(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
|
||||
{
|
||||
@@ -164,6 +173,53 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Resolve special member
|
||||
private void ResolveDateDateByCall(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
||||
{
|
||||
var value = GetNewExpressionValue(expression.Expression);
|
||||
if (expression.Member.Name == "Date")
|
||||
{
|
||||
AppendMember(parameter, isLeft, GetToDate(this.Context.DbMehtods.MergeString(
|
||||
this.GetDateValue(value, DateType.Year),
|
||||
"'-'",
|
||||
this.GetDateValue(value, DateType.Month),
|
||||
"'-'",
|
||||
this.GetDateValue(value, DateType.Day))));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (int myCode in Enum.GetValues(typeof(DateType)))
|
||||
{
|
||||
string strName = Enum.GetName(typeof(DateType), myCode);//获取名称
|
||||
if (expression.Member.Name == strName)
|
||||
{
|
||||
AppendMember(parameter, isLeft, this.Context.DbMehtods.MergeString(this.GetDateValue(value, (DateType)(myCode))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ResolveCallValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
|
||||
{
|
||||
try
|
||||
{
|
||||
baseParameter.ChildExpression = expression;
|
||||
string fieldName = string.Empty;
|
||||
if (isSetTempData)
|
||||
{
|
||||
var value = ExpressionTool.DynamicInvoke(expression);
|
||||
baseParameter.CommonTempData = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = ExpressionTool.DynamicInvoke(expression);
|
||||
base.AppendValue(parameter, isLeft, value);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Check.Exception(true, "Not Support {0}",expression.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private MemberExpression ResolveValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
|
||||
{
|
||||
expression = expression.Expression as MemberExpression;
|
||||
|
@@ -249,12 +249,13 @@ namespace SqlSugar
|
||||
model.Args.AddRange(appendArgs);
|
||||
}
|
||||
var methodValue = GetMethodValue(name, model);
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType&&name=="HasValue"&&!(parameter.OppsiteExpression is BinaryExpression)&& !(parameter.OppsiteExpression is MethodCallExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType)) {
|
||||
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
|
||||
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
|
||||
new KeyValuePair<string, string>("Return","1"),
|
||||
new KeyValuePair<string, string>("End","0")
|
||||
});
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType&&name=="HasValue"&&!(parameter.OppsiteExpression is BinaryExpression)&& !(parameter.OppsiteExpression is MethodCallExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType))
|
||||
{
|
||||
methodValue = packIfElse(methodValue);
|
||||
}
|
||||
if (parameter.OppsiteExpression != null&&name == "IsNullOrEmpty" && parameter.OppsiteExpression.Type == UtilConstants.BoolType&& parameter.OppsiteExpression is ConstantExpression)
|
||||
{
|
||||
methodValue = packIfElse(methodValue);
|
||||
}
|
||||
var isRoot = contextIndex == 2;
|
||||
if (isRoot && parameter.BaseExpression == null &&this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple,ResolveExpressType.WhereSingle)&& (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("ToBool", "ToBoolean")))
|
||||
@@ -284,6 +285,16 @@ namespace SqlSugar
|
||||
base.AppendValue(parameter, isLeft, methodValue);
|
||||
}
|
||||
|
||||
private object packIfElse(object methodValue)
|
||||
{
|
||||
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
|
||||
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
|
||||
new KeyValuePair<string, string>("Return","1"),
|
||||
new KeyValuePair<string, string>("End","0")
|
||||
});
|
||||
return methodValue;
|
||||
}
|
||||
|
||||
private void AppendItem(ExpressionParameter parameter, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, Expression item)
|
||||
{
|
||||
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
|
||||
@@ -386,7 +397,13 @@ namespace SqlSugar
|
||||
{
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
if (item.Type == UtilConstants.DateType && parameter.CommonTempData.ObjToString() == CommonTempDataType.Result.ToString() && item.ToString() == "DateTime.Now.Date")
|
||||
{
|
||||
parameter.CommonTempData = DateTime.Now.Date;
|
||||
}
|
||||
else {
|
||||
base.Start();
|
||||
}
|
||||
var methodCallExpressionArgs = new MethodCallExpressionArgs()
|
||||
{
|
||||
IsMember = parameter.ChildExpression is MemberExpression && !ExpressionTool.IsConstExpression(parameter.ChildExpression as MemberExpression),
|
||||
@@ -405,7 +422,13 @@ namespace SqlSugar
|
||||
methodCallExpressionArgs.IsMember = false;
|
||||
}
|
||||
}
|
||||
if (methodCallExpressionArgs.IsMember == false)
|
||||
if (methodCallExpressionArgs.IsMember == false&&(item is MethodCallExpression&&item.ToString()== "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()")) {
|
||||
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
methodCallExpressionArgs.MemberName = value;
|
||||
methodCallExpressionArgs.MemberValue = null;
|
||||
}
|
||||
else if (methodCallExpressionArgs.IsMember == false)
|
||||
{
|
||||
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
@@ -8,7 +9,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class ContextMethods : IContextMethods
|
||||
public partial class ContextMethods : IContextMethods
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
#region DataReader
|
||||
@@ -144,7 +145,7 @@ namespace SqlSugar
|
||||
if (readerValues.Any(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
var addValue = readerValues.ContainsKey(name) ? readerValues[name] : readerValues.First(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Value;
|
||||
if (addValue == DBNull.Value||addValue==null)
|
||||
if (addValue == DBNull.Value || addValue == null)
|
||||
{
|
||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||
{
|
||||
@@ -449,24 +450,25 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var item = model as ConditionalCollections;
|
||||
if (item != null&& item.ConditionalList.HasValue())
|
||||
if (item != null && item.ConditionalList.HasValue())
|
||||
{
|
||||
foreach (var con in item.ConditionalList)
|
||||
{
|
||||
var index = item.ConditionalList.IndexOf(con);
|
||||
var isFirst = index == 0;
|
||||
var isLast = index == (item.ConditionalList.Count - 1);
|
||||
if (models.IndexOf(item) == 0 &&index==0&& beginIndex == 0)
|
||||
if (models.IndexOf(item) == 0 && index == 0 && beginIndex == 0)
|
||||
{
|
||||
builder.AppendFormat(" ( ");
|
||||
|
||||
}else if (isFirst)
|
||||
}
|
||||
else if (isFirst)
|
||||
{
|
||||
builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper());
|
||||
}
|
||||
List<IConditionalModel> conModels = new List<IConditionalModel>();
|
||||
conModels.Add(con.Value);
|
||||
var childSqlInfo = ConditionalModelToSql(conModels, 1000 * (1 + index)+ models.IndexOf(item));
|
||||
var childSqlInfo = ConditionalModelToSql(conModels, 1000 * (1 + index) + models.IndexOf(item));
|
||||
if (!isFirst)
|
||||
{
|
||||
|
||||
@@ -497,5 +499,21 @@ namespace SqlSugar
|
||||
return item.FieldValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region
|
||||
public void PageEach<T>(IEnumerable<T> pageItems,int pageSize, Action<List<T>> action)
|
||||
{
|
||||
if (pageItems != null&& pageItems.Any())
|
||||
{
|
||||
int totalRecord = pageItems.Count();
|
||||
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||
for (int i = 1; i <= pageCount; i++)
|
||||
{
|
||||
var list = pageItems.Skip((i - 1) * pageSize).Take(pageSize).ToList();
|
||||
action(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,7 @@ namespace SqlSugar
|
||||
int GetInt(string sql, object pars);
|
||||
int GetInt(string sql, params SugarParameter[] parameters);
|
||||
int GetInt(string sql, List<SugarParameter> parameters);
|
||||
long GetLong(string sql, object pars);
|
||||
Double GetDouble(string sql, object parameters);
|
||||
Double GetDouble(string sql, params SugarParameter[] parameters);
|
||||
Double GetDouble(string sql, List<SugarParameter> parameters);
|
||||
@@ -94,10 +95,10 @@ namespace SqlSugar
|
||||
void RollbackTran();
|
||||
void CommitTran();
|
||||
|
||||
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);
|
||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
|
||||
void UseStoredProcedure(Action action);
|
||||
T UseStoredProcedure<T>(Func<T> action);
|
||||
|
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public interface IContextMethods
|
||||
public partial interface IContextMethods
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
||||
@@ -25,6 +25,7 @@ namespace SqlSugar
|
||||
void RemoveCacheAll<T>();
|
||||
void RemoveCache<T>(string key);
|
||||
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models,int beginIndex=0);
|
||||
void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -70,10 +71,10 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? null : " AND ");
|
||||
whereString += item;
|
||||
whereString += Regex.Replace(item, " \\" + this.Builder.SqlTranslationLeft, "T." + this.Builder.SqlTranslationLeft);
|
||||
}
|
||||
}
|
||||
else if (PrimaryKeys.HasValue())
|
||||
if (PrimaryKeys.HasValue())
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
|
@@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
foreach (var item in pkList)
|
||||
{
|
||||
var isFirst = pkList.First() == item;
|
||||
var whereString = isFirst ? " " : " AND ";
|
||||
var whereString = "";
|
||||
whereString += GetOracleUpdateColums(item);
|
||||
whereList.Add(whereString);
|
||||
}
|
||||
|
@@ -118,6 +118,7 @@ namespace SqlSugar
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>(string shortName)
|
||||
{
|
||||
Check.Exception(shortName.HasValue() && shortName.Length > 20, ErrorMessage.GetThrowMessage("shortName参数长度不能超过20,你可能是想用这个方法 db.SqlQueryable(sql)而不是db.Queryable(shortName)", "Queryable.shortName max length 20"));
|
||||
var queryable = Queryable<T>();
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
return queryable;
|
||||
@@ -450,7 +451,11 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new()
|
||||
{
|
||||
Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null");
|
||||
if (insertObjs == null|| insertObjs.IsNullOrEmpty())
|
||||
{
|
||||
insertObjs = new List<T>();
|
||||
insertObjs.Add(default(T));
|
||||
}
|
||||
return this.Context.Insertable(insertObjs.ToArray());
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(T insertObj) where T : class, new()
|
||||
@@ -836,10 +841,7 @@ namespace SqlSugar
|
||||
var newName = itemParameter.ParameterName + "_q_" + index;
|
||||
SugarParameter parameter = new SugarParameter(newName, itemParameter.Value);
|
||||
parameter.DbType = itemParameter.DbType;
|
||||
itemSql = Regex.Replace(itemSql,string.Format(@"{0} ","\\"+itemParameter.ParameterName), newName+" ");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName+")");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName+",");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName);
|
||||
itemSql = UtilMethods.ReplaceSqlParameter(itemSql, itemParameter, newName);
|
||||
addParameters.Add(parameter);
|
||||
}
|
||||
parsmeters.AddRange(addParameters);
|
||||
|
@@ -17,7 +17,14 @@ namespace SqlSugar
|
||||
Type type = Nullable.GetUnderlyingType(oldType);
|
||||
return type == null ? oldType : type;
|
||||
}
|
||||
|
||||
public static string ReplaceSqlParameter(string itemSql, SugarParameter itemParameter, string newName)
|
||||
{
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0} ", "\\" + itemParameter.ParameterName), newName + " ", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName + ")", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName + ",", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName, RegexOptions.IgnoreCase);
|
||||
return itemSql;
|
||||
}
|
||||
internal static Type GetRootBaseType(Type entityType)
|
||||
{
|
||||
var baseType = entityType.BaseType;
|
||||
@@ -78,7 +85,7 @@ namespace SqlSugar
|
||||
//Compatible with.NET CORE parameters case
|
||||
var name = parameter.ParameterName;
|
||||
string newName = name +append+ addIndex;
|
||||
appendSql =Regex.Replace(appendSql,name,newName,RegexOptions.IgnoreCase);
|
||||
appendSql = ReplaceSqlParameter(appendSql, parameter, newName);
|
||||
parameter.ParameterName = newName;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user