mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 02:35:04 +08:00
Update Core
This commit is contained in:
@@ -90,7 +90,14 @@ namespace SqlSugar
|
||||
{
|
||||
if (this.Connection.State != ConnectionState.Open)
|
||||
{
|
||||
this.Connection.Open();
|
||||
try
|
||||
{
|
||||
this.Connection.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true,ErrorMessage.ConnnectionOpen, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,8 +158,8 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Exception = ex;
|
||||
result.Messaage = ex.Message;
|
||||
result.ErrorException = ex;
|
||||
result.ErrorMessage = ex.Message;
|
||||
result.IsSuccess = false;
|
||||
this.RollbackTran();
|
||||
}
|
||||
@@ -171,8 +178,8 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Exception = ex;
|
||||
result.Messaage = ex.Message;
|
||||
result.ErrorException = ex;
|
||||
result.ErrorMessage = ex.Message;
|
||||
result.IsSuccess = false;
|
||||
this.RollbackTran();
|
||||
}
|
||||
@@ -204,6 +211,11 @@ namespace SqlSugar
|
||||
this.IsClearParameters = true;
|
||||
return result;
|
||||
}
|
||||
public IAdo UseStoredProcedure()
|
||||
{
|
||||
this.CommandType = CommandType.StoredProcedure;
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Core
|
||||
|
@@ -34,7 +34,7 @@ namespace SqlSugar
|
||||
{
|
||||
Execute(entityType);
|
||||
});
|
||||
Check.Exception(!executeResult.IsSuccess, executeResult.Messaage);
|
||||
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
||||
}
|
||||
public virtual void InitTables(Type[] entityTypes)
|
||||
{
|
||||
|
@@ -97,7 +97,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.DbColumnName == dbColumnName);
|
||||
return mappingInfo == null ? dbColumnName : mappingInfo.DbColumnName;
|
||||
return mappingInfo == null ? dbColumnName : mappingInfo.PropertyName;
|
||||
}
|
||||
}
|
||||
public PropertyInfo GetProperty<T>(string dbColumnName)
|
||||
|
@@ -53,16 +53,34 @@ namespace SqlSugar
|
||||
RestoreMapping();
|
||||
return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
}
|
||||
public long ExecuteReturnBigIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
}
|
||||
public T ExecuteReturnEntity()
|
||||
{
|
||||
ExecuteCommandIdentityIntoEntity();
|
||||
return InsertObjs.First();
|
||||
}
|
||||
public bool ExecuteCommandIdentityIntoEntity()
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys=GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) return result;
|
||||
var idValue = ExecuteReturnIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteReutrnEntity does not support multiple identity keys");
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { return this.ExecuteCommand() > 0; }
|
||||
var idValue = ExecuteReturnBigIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result,idValue,null);
|
||||
return result;
|
||||
object setValue= 0;
|
||||
if (idValue > int.MaxValue)
|
||||
setValue = idValue;
|
||||
else
|
||||
setValue = Convert.ToInt32(idValue);
|
||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result,setValue, null);
|
||||
return idValue>0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@@ -236,10 +236,10 @@ namespace SqlSugar
|
||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||
string groupByValue = GetGroupByString + HavingInfos;
|
||||
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
|
||||
if (this.IsCount) { orderByValue = null; this.OrderByValue = oldOrderBy; }
|
||||
if (this.IsCount) { orderByValue = null; }
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
||||
sql.Replace(UtilConstants.OrderReplace, isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
|
||||
if (this.IsCount) { return sql.ToString(); }
|
||||
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
|
||||
if (this.IsCount) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
|
||||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
||||
if (ExternalPageIndex > 0)
|
||||
{
|
||||
|
@@ -30,6 +30,7 @@ namespace SqlSugar
|
||||
PreToSql();
|
||||
string sql = UpdateBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
return this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
|
||||
}
|
||||
public IUpdateable<T> AS(string tableName)
|
||||
|
@@ -8,8 +8,8 @@ namespace SqlSugar
|
||||
public class DbResult<T>
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public Exception Exception { get; set; }
|
||||
public string Messaage { get; set; }
|
||||
public Exception ErrorException { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public T Data { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName");
|
||||
return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达式格式错误,正确格式: it=>it.fieldName");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,13 @@ namespace SqlSugar
|
||||
return ErrorMessage.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0},SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConnnectionOpen
|
||||
{
|
||||
get
|
||||
{
|
||||
return ErrorMessage.GetThrowMessage("Connection open error . {0}", " 连接字符串出错了,实在找不到原因请先Google错误{0}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,16 +7,13 @@ namespace SqlSugar
|
||||
{
|
||||
internal class ExpressionConst
|
||||
{
|
||||
public const string BinaryFormatString = " ( {0} {1} {2} ) ";
|
||||
public const string Format0 = "{0}";
|
||||
public const string Format1 = "$__$";
|
||||
public const string Format2 = "o__o";
|
||||
public const string Format3 = "(";
|
||||
public const string Format4 = ")";
|
||||
public const string SqlFuncFullName = "SqlSugar.SqlFunc";
|
||||
public const string MethodConst = "MethodConst";
|
||||
public const string Const = "Const";
|
||||
public readonly static Type MemberExpressionType = typeof(MemberExpression);
|
||||
public readonly static Type ConstantExpressionType = typeof(ConstantExpression);
|
||||
public const string FormatSymbol = "{0}";
|
||||
public const string RightParenthesis = ")";
|
||||
public const string LeftParenthesis = "(";
|
||||
public const string MethodConst = "MethodConst";
|
||||
public const string SqlFuncFullName = "SqlSugar.SqlFunc";
|
||||
public const string BinaryFormatString = " ( {0} {1} {2} ) ";
|
||||
public const string ExpressionReplace = "46450BDC-77B7-4025-B2A6-3F048CA85AD0";
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
private IDbMethods _DbMehtods { get; set; }
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
#region Properties
|
||||
public IDbMethods DbMehtods
|
||||
{
|
||||
get
|
||||
@@ -100,22 +100,44 @@ namespace SqlSugar
|
||||
public virtual string SqlTranslationRight { get { return "]"; } }
|
||||
#endregion
|
||||
|
||||
#region public functions
|
||||
#region Core methods
|
||||
public void Resolve(Expression expression, ResolveExpressType resolveType)
|
||||
{
|
||||
this.ResolveType = resolveType;
|
||||
this.Expression = expression;
|
||||
BaseResolve resolve = new BaseResolve(new ExpressionParameter() { CurrentExpression = this.Expression, Context = this });
|
||||
resolve.Start();
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
base._Result = null;
|
||||
base._Parameters = new List<SugarParameter>();
|
||||
}
|
||||
public ExpressionContext GetCopyContext()
|
||||
{
|
||||
ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true);
|
||||
copyContext.Index = this.Index;
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
return copyContext;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Override methods
|
||||
public virtual string GetTranslationTableName(string entityName, bool isMapping = true)
|
||||
{
|
||||
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
|
||||
if (IsTranslationText(entityName)) return entityName;
|
||||
isMapping = isMapping && this.MappingTables.IsValuable();
|
||||
var isComplex = entityName.Contains(".");
|
||||
var isComplex = entityName.Contains(UtilConstants.Dot);
|
||||
if (isMapping && isComplex)
|
||||
{
|
||||
var columnInfo = entityName.Split('.');
|
||||
var columnInfo = entityName.Split(UtilConstants.DotChar);
|
||||
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
|
||||
if (mappingInfo != null)
|
||||
{
|
||||
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
|
||||
}
|
||||
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
|
||||
return string.Join(UtilConstants.Dot, columnInfo.Select(it => GetTranslationText(it)));
|
||||
}
|
||||
else if (isMapping)
|
||||
{
|
||||
@@ -124,7 +146,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (isComplex)
|
||||
{
|
||||
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
|
||||
return string.Join(UtilConstants.Dot, entityName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,15 +155,15 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual string GetTranslationColumnName(string columnName)
|
||||
{
|
||||
Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "column Name"));
|
||||
Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "Column Name"));
|
||||
if (columnName.Substring(0, 1) == this.SqlParameterKeyWord)
|
||||
{
|
||||
return columnName;
|
||||
}
|
||||
if (IsTranslationText(columnName)) return columnName;
|
||||
if (columnName.Contains("."))
|
||||
if (columnName.Contains(UtilConstants.Dot))
|
||||
{
|
||||
return string.Join(".", columnName.Split('.').Select(it => GetTranslationText(it)));
|
||||
return string.Join(UtilConstants.Dot, columnName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -168,13 +190,6 @@ namespace SqlSugar
|
||||
{
|
||||
return SqlTranslationLeft + name + SqlTranslationRight;
|
||||
}
|
||||
public virtual void Resolve(Expression expression, ResolveExpressType resolveType)
|
||||
{
|
||||
this.ResolveType = resolveType;
|
||||
this.Expression = expression;
|
||||
BaseResolve resolve = new BaseResolve(new ExpressionParameter() { CurrentExpression = this.Expression, Context = this });
|
||||
resolve.Start();
|
||||
}
|
||||
public virtual string GetAsString(string asName, string fieldValue)
|
||||
{
|
||||
if (fieldValue.Contains(".*") || fieldValue == "*") return fieldValue;
|
||||
@@ -191,18 +206,6 @@ namespace SqlSugar
|
||||
if (fieldValue.Contains(".*") || fieldValue == "*") return fieldValue;
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName));
|
||||
}
|
||||
public virtual void Clear()
|
||||
{
|
||||
base._Result = null;
|
||||
base._Parameters = new List<SugarParameter>();
|
||||
}
|
||||
public ExpressionContext GetCopyContext()
|
||||
{
|
||||
ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true);
|
||||
copyContext.Index = this.Index;
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
return copyContext;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -113,11 +113,11 @@ namespace SqlSugar
|
||||
Context.ParameterIndex++;
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString());
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -132,9 +132,9 @@ namespace SqlSugar
|
||||
if (parameter.CurrentExpression is MethodCallExpression)
|
||||
{
|
||||
var appendValue = value;
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString());
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -159,11 +159,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -186,11 +186,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -209,11 +209,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,7 +226,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (isLeft == true)
|
||||
{
|
||||
this.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index);
|
||||
this.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index);
|
||||
}
|
||||
}
|
||||
protected string AppendParameter(object paramterValue)
|
||||
@@ -238,14 +238,14 @@ namespace SqlSugar
|
||||
}
|
||||
protected void AppendNot(object Value)
|
||||
{
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.Format0);
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||
if (isAppend)
|
||||
{
|
||||
this.Context.Result.Append("NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, "NOT");
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "NOT");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,15 +22,15 @@ namespace SqlSugar
|
||||
var lsrb = !leftIsBinary && rightBinary;
|
||||
var lbrb = rightBinary && leftIsBinary;
|
||||
var lsbs = !leftIsBinary && !rightBinary;
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.Format0);
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||
if (isAppend)
|
||||
{
|
||||
base.Context.Result.Append(ExpressionConst.Format3);
|
||||
base.Context.Result.Append(ExpressionConst.Format0);
|
||||
base.Context.Result.Append(ExpressionConst.LeftParenthesis);
|
||||
base.Context.Result.Append(ExpressionConst.FormatSymbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, ExpressionConst.Format3 + ExpressionConst.Format0);
|
||||
base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol);
|
||||
}
|
||||
parameter.LeftExpression = leftExpression;
|
||||
parameter.RightExpression = rightExpression;
|
||||
@@ -43,18 +43,18 @@ namespace SqlSugar
|
||||
base.IsLeft = null;
|
||||
if (lsbs && parameter.ValueIsNull)
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index+1), isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index+1), isEqual ? "IS" : "IS NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index + 1), operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), operatorValue);
|
||||
}
|
||||
base.Context.Result.Append(ExpressionConst.Format4);
|
||||
base.Context.Result.Append(ExpressionConst.RightParenthesis);
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true)
|
||||
{
|
||||
base.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index + " ");
|
||||
base.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -176,11 +176,11 @@ namespace SqlSugar
|
||||
fieldName = string.Format(" {0} ", fieldName);
|
||||
if (isLeft == true)
|
||||
{
|
||||
fieldName += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
fieldName += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (base.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (base.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, fieldName);
|
||||
base.Context.Result.Replace(ExpressionConst.FormatSymbol, fieldName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -351,6 +351,7 @@ namespace SqlSugar
|
||||
case "ToTime":
|
||||
return this.Context.DbMehtods.ToTime(model);
|
||||
case "ToString":
|
||||
Check.Exception(model.Args.Count > 1, "ToString (Format) is not supported, Use ToString().If time formatting can be used it.Date.Year+\"-\"+it.Data.Month+\"-\"+it.Date.Day ");
|
||||
return this.Context.DbMehtods.ToString(model);
|
||||
case "ToDecimal":
|
||||
return this.Context.DbMehtods.ToDecimal(model);
|
||||
|
@@ -202,7 +202,7 @@ namespace SqlSugar
|
||||
public T DeserializeObject<T>(string value)
|
||||
{
|
||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
return JsonConvert.DeserializeObject<T>(value,jSetting);
|
||||
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@@ -86,5 +86,6 @@ namespace SqlSugar
|
||||
DbResult<T> UseTran<T>(Func<T> action);
|
||||
void UseStoredProcedure(Action action);
|
||||
T UseStoredProcedure<T>(Func<T> action);
|
||||
IAdo UseStoredProcedure();
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ namespace SqlSugar
|
||||
int ExecuteCommand();
|
||||
int ExecuteReturnIdentity();
|
||||
T ExecuteReturnEntity();
|
||||
bool ExecuteCommandIdentityIntoEntity();
|
||||
long ExecuteReturnBigIdentity();
|
||||
IInsertable<T> AS(string tableName);
|
||||
IInsertable<T> With(string lockString);
|
||||
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);
|
||||
|
@@ -17,12 +17,19 @@ namespace SqlSugar
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
if (!mySqlConnectionString.ToLower().Contains("charset"))
|
||||
try
|
||||
{
|
||||
mySqlConnectionString=mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;";
|
||||
var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
if (!mySqlConnectionString.ToLower().Contains("charset"))
|
||||
{
|
||||
mySqlConnectionString = mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;";
|
||||
}
|
||||
base._DbConnection = new MySqlConnection(mySqlConnectionString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message);
|
||||
}
|
||||
base._DbConnection = new MySqlConnection(mySqlConnectionString);
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT {0}{"+UtilConstants.OrderReplace+"} FROM {1}{2}{3}{4}";
|
||||
return "SELECT {0}{"+UtilConstants.ReplaceKey+"} FROM {1}{2}{3}{4}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,14 @@ namespace SqlSugar
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
base._DbConnection = new SqlConnection(base.Context.CurrentConnectionConfig.ConnectionString);
|
||||
try
|
||||
{
|
||||
base._DbConnection = new SqlConnection(base.Context.CurrentConnectionConfig.ConnectionString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message);
|
||||
}
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
|
@@ -41,11 +41,18 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("nvarchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nvarchar2",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("ntext",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("blob_text",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("num",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("currency",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("datetext",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("word",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("graphic",CSharpDataType.@string),
|
||||
|
||||
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
|
||||
new KeyValuePair<string, CSharpDataType>("UNSIGNEDINTEGER8",CSharpDataType.@byte),
|
||||
new KeyValuePair<string, CSharpDataType>("unsignedinteger8",CSharpDataType.@byte),
|
||||
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
|
||||
new KeyValuePair<string, CSharpDataType>("int16",CSharpDataType.@short),
|
||||
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
||||
@@ -58,7 +65,10 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("double",CSharpDataType.@double),
|
||||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
|
||||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("dec",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("money",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("smallmoney",CSharpDataType.@decimal),
|
||||
|
||||
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
|
||||
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
|
||||
@@ -66,9 +76,12 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
|
||||
|
||||
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("clob",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("raw",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("oleobject",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("photo",CSharpDataType.byteArray),
|
||||
new KeyValuePair<string, CSharpDataType>("picture",CSharpDataType.byteArray),
|
||||
|
||||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
|
||||
new KeyValuePair<string, CSharpDataType>("guid",CSharpDataType.Guid)
|
||||
|
@@ -16,10 +16,17 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
try
|
||||
{
|
||||
var SqliteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
base._DbConnection = new SqliteConnection(SqliteConnectionString);
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
var SqliteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
base._DbConnection = new SqliteConnection(SqliteConnectionString);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message);
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
|
@@ -152,7 +152,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6,T7>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
@@ -160,7 +160,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T8>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6,T7, T8>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
@@ -169,7 +169,7 @@ namespace SqlSugar
|
||||
#region 9-12
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6,T7, T8, T9>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
@@ -177,7 +177,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7,T8, T9, T10>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
@@ -185,7 +185,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10, T11>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6,T7, T8, T9, T10, T11>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
@@ -193,7 +193,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10, T11, T12>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6,T7, T8, T9, T10, T11, T12>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(base.CurrentConnectionConfig);
|
||||
base.CreateQueryJoin(joinExpression, types, queryable);
|
||||
|
@@ -6,31 +6,32 @@ namespace SqlSugar
|
||||
{
|
||||
internal static class UtilConstants
|
||||
{
|
||||
|
||||
public const string Dot = ".";
|
||||
public const char DotChar = '.';
|
||||
internal const string Space = " ";
|
||||
internal const string AssemblyName = "SqlSugar";
|
||||
internal const string OrderReplace = "{$:OrderByString:$}";
|
||||
internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}";
|
||||
|
||||
internal static Type StringType = typeof(string);
|
||||
internal static Type ShortType = typeof(short);
|
||||
internal static Type IntType = typeof(int);
|
||||
internal static Type LongType = typeof(long);
|
||||
internal static Type DecType = typeof(decimal);
|
||||
internal static Type GuidType = typeof(Guid);
|
||||
internal static Type DateType = typeof(DateTime);
|
||||
internal static Type ByteType = typeof(Byte);
|
||||
internal static Type ByteArrayType = typeof(byte[]);
|
||||
internal static Type BoolType = typeof(bool);
|
||||
internal static Type ByteType = typeof(Byte);
|
||||
internal static Type ObjType = typeof(object);
|
||||
internal static Type DobType = typeof(double);
|
||||
internal static Type FloatType=typeof(float);
|
||||
internal static Type FloatType = typeof(float);
|
||||
internal static Type ShortType = typeof(short);
|
||||
internal static Type DecType = typeof(decimal);
|
||||
internal static Type StringType = typeof(string);
|
||||
internal static Type DateType = typeof(DateTime);
|
||||
internal static Type ByteArrayType = typeof(byte[]);
|
||||
internal static Type ModelType= typeof(ModelContext);
|
||||
internal static Type DicSS = typeof(KeyValuePair<string, string>);
|
||||
internal static Type DicSi = typeof(KeyValuePair<string, int>);
|
||||
internal static Type Dicii = typeof(KeyValuePair<int, int>);
|
||||
internal static Type DicIS = typeof(KeyValuePair<int, string>);
|
||||
internal static Type DicSi = typeof(KeyValuePair<string, int>);
|
||||
internal static Type DicSS = typeof(KeyValuePair<string, string>);
|
||||
internal static Type DicOO = typeof(KeyValuePair<object, object>);
|
||||
internal static Type DicSo = typeof(KeyValuePair<string, object>);
|
||||
internal static Type DicIS = typeof(KeyValuePair<int, string>);
|
||||
internal static Type DicArraySS = typeof(Dictionary<string, string>);
|
||||
internal static Type DicArraySO = typeof(Dictionary<string, object>);
|
||||
}
|
||||
|
Reference in New Issue
Block a user