Browse Source

Update Core

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f6e387ea25
  1. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 7
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs
  3. 13
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs
  4. 19
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  5. 61
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  6. 15
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  7. 10
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs
  8. 85
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  9. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs
  10. 3
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/PageModel.cs
  11. 3
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Enum/ConditionalType.cs
  12. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  13. 7
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs
  14. 3
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlBuilder.cs
  15. 9
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs
  16. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs
  17. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs
  18. 39
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs
  19. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs
  20. 7
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  21. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs
  22. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs
  23. 70
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs
  24. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj
  25. 34
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs
  26. 11
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs
  27. BIN
      Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -655,7 +655,10 @@ namespace SqlSugar
{
foreach (var outputParameter in parameters.Where(it => it.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput,ParameterDirection.ReturnValue)))
{
var gobalOutputParamter = this.OutputParameters.Single(it => it.ParameterName == outputParameter.ParameterName);
var gobalOutputParamter = this.OutputParameters.FirstOrDefault(it => it.ParameterName == outputParameter.ParameterName);
if (gobalOutputParamter == null) {//Oracle bug
gobalOutputParamter=this.OutputParameters.FirstOrDefault(it => it.ParameterName == outputParameter.ParameterName.TrimStart(outputParameter.ParameterName.First()));
}
outputParameter.Value = gobalOutputParamter.Value;
this.OutputParameters.Remove(gobalOutputParamter);
}

7
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs

@ -49,6 +49,8 @@ namespace SqlSugar
private static readonly MethodInfo getConvertByte = typeof(IDataRecordExtensions).GetMethod("GetConvertByte");
private static readonly MethodInfo getConvertChar = typeof(IDataRecordExtensions).GetMethod("GetConvertChar");
private static readonly MethodInfo getConvertDateTime = typeof(IDataRecordExtensions).GetMethod("GetConvertDateTime");
private static readonly MethodInfo getConvertTime = typeof(IDataRecordExtensions).GetMethod("GetConvertTime");
private static readonly MethodInfo getTime = typeof(IDataRecordExtensions).GetMethod("GetTime");
private static readonly MethodInfo getConvertDecimal = typeof(IDataRecordExtensions).GetMethod("GetConvertDecimal");
private static readonly MethodInfo getConvertDouble = typeof(IDataRecordExtensions).GetMethod("GetConvertDouble");
private static readonly MethodInfo getConvertGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertGuid");
@ -176,6 +178,9 @@ namespace SqlSugar
MethodInfo method = null;
Type bindPropertyType = UtilMethods.GetUnderType(bindProperty, ref isNullableType);
string dbTypeName = UtilMethods.GetParenthesesValue(DataRecord.GetDataTypeName(ordinal));
if (dbTypeName.IsNullOrEmpty()) {
dbTypeName = bindPropertyType.Name;
}
string propertyName = bindProperty.Name;
string validPropertyName = bind.GetPropertyTypeName(dbTypeName);
validPropertyName = validPropertyName == "byte[]" ? "byteArray" : validPropertyName;
@ -245,6 +250,8 @@ namespace SqlSugar
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
if (bindProperyTypeName == "datetime")
method = isNullableType ? getConvertDateTime : getDateTime;
if (bindProperyTypeName == "datetime"&&dbTypeName == "time")
method = isNullableType ? getConvertTime : getTime;
break;
case CSharpDataType.@decimal:
CheckType(bind.DecimalThrow, bindProperyTypeName, validPropertyName, propertyName);

13
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs

@ -60,6 +60,19 @@ namespace SqlSugar
}
return result;
}
public static DateTime? GetConvertTime(this IDataRecord dr, int i)
{
var result = dr.GetValue(i);
if (result == DBNull.Value)
{
return null; ;
}
return Convert.ToDateTime(result.ToString());
}
public static DateTime GetTime(this IDataRecord dr, int i)
{
return Convert.ToDateTime(dr.GetValue(i).ToString());
}
public static decimal? GetConvertDecimal(this IDataRecord dr, int i)
{

19
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -45,9 +45,9 @@ namespace SqlSugar
cacheKey = GetCacheKey(cacheKey);
var sql = string.Format(this.GetColumnInfosByTableNameSql, tableName);
if (isCache)
return GetListOrCache<DbColumnInfo>(cacheKey, sql);
return GetListOrCache<DbColumnInfo>(cacheKey, sql).GroupBy(it=>it.DbColumnName).Select(it=>it.First()).ToList();
else
return this.Context.Ado.SqlQuery<DbColumnInfo>(sql);
return this.Context.Ado.SqlQuery<DbColumnInfo>(sql).GroupBy(it => it.DbColumnName).Select(it => it.First()).ToList();
}
public virtual List<string> GetIsIdentities(string tableName)
@ -82,8 +82,8 @@ namespace SqlSugar
}
public virtual bool IsAnyColumn(string tableName, string columnName)
{
columnName = this.SqlBuilder.GetTranslationColumnName(columnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);
tableName = this.SqlBuilder.GetNoTranslationColumnName(tableName);
var isAny = IsAnyTable(tableName);
Check.Exception(!isAny, string.Format("Table {0} does not exist", tableName));
var columns = GetColumnInfosByTableName(tableName);
@ -92,7 +92,7 @@ namespace SqlSugar
}
public virtual bool IsPrimaryKey(string tableName, string columnName)
{
columnName = this.SqlBuilder.GetTranslationColumnName(columnName);
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);
var isAny = IsAnyTable(tableName);
Check.Exception(!isAny, string.Format("Table {0} does not exist", tableName));
var columns = GetColumnInfosByTableName(tableName);
@ -101,7 +101,7 @@ namespace SqlSugar
}
public virtual bool IsIdentity(string tableName, string columnName)
{
columnName = this.SqlBuilder.GetTranslationColumnName(columnName);
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);
var isAny = IsAnyTable(tableName);
Check.Exception(!isAny, string.Format("Table {0} does not exist", tableName));
var columns = GetColumnInfosByTableName(tableName);
@ -257,8 +257,8 @@ namespace SqlSugar
{
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType;
string dataSize = GetSize(columnInfo);
string dataType = columnInfo.DataType;
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = null;
@ -277,6 +277,11 @@ namespace SqlSugar
{
dataSize = item.Length > 0 ? string.Format("({0})", "max") : null;
}
else if (item.Length == 0 && item.DecimalDigits > 0)
{
item.Length = 10;
dataSize = string.Format("({0},{1})", item.Length, item.DecimalDigits);
}
else if (item.Length > 0 && item.DecimalDigits == 0)
{
dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;

61
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -264,27 +264,58 @@ namespace SqlSugar
foreach (var item in InsertObjs)
{
List<DbColumnInfo> insertItem = new List<DbColumnInfo>();
foreach (var column in EntityInfo.Columns)
if (item is Dictionary<string, object>)
{
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
var columnInfo = new DbColumnInfo()
{
Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
insertItem.Add(columnInfo);
SetInsertItemByDic(i, item, insertItem);
}
else
{
SetInsertItemByEntity(i, item, insertItem);
}
this.InsertBuilder.DbColumnInfoList.AddRange(insertItem);
++i;
}
}
private void SetInsertItemByDic(int i, T item, List<DbColumnInfo> insertItem)
{
foreach (var column in item as Dictionary<string,object>)
{
var columnInfo = new DbColumnInfo()
{
Value = column.Value,
DbColumnName = column.Key,
PropertyName = column.Key,
PropertyType = UtilMethods.GetUnderType(column.Value.GetType()),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
insertItem.Add(columnInfo);
}
}
private void SetInsertItemByEntity(int i, T item, List<DbColumnInfo> insertItem)
{
foreach (var column in EntityInfo.Columns)
{
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
var columnInfo = new DbColumnInfo()
{
Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
insertItem.Add(columnInfo);
}
}
private string GetDbColumnName(string propertyName)
{
if (!IsMappingColumns)

15
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -167,6 +167,7 @@ namespace SqlSugar
public virtual T InSingle(object pkValue)
{
Check.Exception(this.QueryBuilder.SelectValue.HasValue(), "'InSingle' and' Select' can't be used together,You can use .Select(it=>...).Single(it.id==1)");
var list = In(pkValue).ToList();
if (list == null) return default(T);
else return list.SingleOrDefault();
@ -987,7 +988,9 @@ namespace SqlSugar
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
return Min<TResult>(lamResult.GetResultString());
var result= Min<TResult>(lamResult.GetResultString());
QueryBuilder.SelectValue = null;
return result;
}
protected TResult _Avg<TResult>(Expression expression)
{
@ -999,13 +1002,17 @@ namespace SqlSugar
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
return Max<TResult>(lamResult.GetResultString());
var reslut= Max<TResult>(lamResult.GetResultString());
QueryBuilder.SelectValue = null;
return reslut;
}
protected TResult _Sum<TResult>(Expression expression)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
return Sum<TResult>(lamResult.GetResultString());
var reslut= Sum<TResult>(lamResult.GetResultString());
QueryBuilder.SelectValue = null;
return reslut;
}
protected ISugarQueryable<T> _As(string tableName, string entityName)
{
@ -1173,7 +1180,7 @@ namespace SqlSugar
{
if (result.HasValue())
{
if (entityType.GetTypeInfo().BaseType.HasValue() && entityType.GetTypeInfo().BaseType == UtilConstants.ModelType)
if (UtilMethods.GetRootBaseType(entityType).HasValue() &&UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType)
{
foreach (var item in result)
{

10
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -86,10 +86,20 @@ namespace SqlSugar
{
return "t";
}
public string GetWhere(string fieldName,string conditionalType,int? parameterIndex=null)
{
return string.Format(" {0} {1} {2}{3} ",fieldName,conditionalType,this.SqlParameterKeyWord,fieldName+ parameterIndex);
}
public virtual string GetUnionAllSql(List<string> sqlList)
{
return string.Join("UNION ALL \r\n", sqlList);
}
public virtual string GetUnionSql(List<string> sqlList)
{
return string.Join("UNION \r\n", sqlList);
}
public virtual void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex)
{
UtilMethods.RepairReplicationParameters(ref appendSql, parameters, addIndex);

85
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -141,7 +141,7 @@ namespace SqlSugar
public IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns) {
var binaryExp = columns.Body as BinaryExpression;
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
Check.Exception(!(binaryExp.Left is MemberExpression), "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(')');
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
@ -196,6 +196,26 @@ namespace SqlSugar
return this;
}
public IUpdateable<T> Where(string whereSql, object parameters = null)
{
if (whereSql.HasValue()) {
UpdateBuilder.WhereValues.Add(whereSql);
}
if (parameters != null) {
UpdateBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters));
}
return this;
}
public IUpdateable<T> Where(string fieldName,string conditionalType, object fieldValue)
{
var whereSql=this.SqlBuilder.GetWhere(fieldName, conditionalType,0);
this.Where(whereSql);
string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName+ "0";
this.UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue));
return this;
}
public IUpdateable<T> With(string lockString)
{
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
@ -226,26 +246,59 @@ namespace SqlSugar
foreach (var item in UpdateObjs)
{
List<DbColumnInfo> updateItem = new List<DbColumnInfo>();
foreach (var column in EntityInfo.Columns)
var isDic = item is Dictionary<string,object>;
if (isDic)
{
var columnInfo = new DbColumnInfo()
{
Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
updateItem.Add(columnInfo);
SetUpdateItemByDic(i, item, updateItem);
}
else
{
SetUpdateItemByEntity(i, item, updateItem);
}
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
++i;
}
}
private void SetUpdateItemByDic(int i, T item, List<DbColumnInfo> updateItem)
{
foreach (var column in item as Dictionary<string,object>)
{
var columnInfo = new DbColumnInfo()
{
Value = column.Value,
DbColumnName =column.Key,
PropertyName = column.Key,
PropertyType = UtilMethods.GetUnderType(column.Value.GetType()),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
updateItem.Add(columnInfo);
}
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
}
private void SetUpdateItemByEntity(int i, T item, List<DbColumnInfo> updateItem)
{
foreach (var column in EntityInfo.Columns)
{
var columnInfo = new DbColumnInfo()
{
Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
updateItem.Add(columnInfo);
}
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
}
private void PreToSql()
{
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs

@ -27,6 +27,7 @@ namespace SqlSugar
result.IdentificationList.Add(queryBuilder.PartitionByValue);
result.IdentificationList.Add(queryBuilder.Take.ObjToString());
result.IdentificationList.Add(queryBuilder.Skip.ObjToString());
result.IdentificationList.Add(queryBuilder.IsCount.ObjToString());
if (queryBuilder.Parameters.HasValue())
{
foreach (var item in queryBuilder.Parameters)

3
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/PageModel.cs

@ -10,6 +10,9 @@ namespace SqlSugar
{
public int PageIndex { get; set; }
public int PageSize { get; set; }
/// <summary>
/// output
/// </summary>
public int PageCount { get; set; }
}
}

3
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Enum/ConditionalType.cs

@ -19,6 +19,7 @@ namespace SqlSugar
LikeRight=9,
NoEqual=10,
IsNullOrEmpty=11,
IsNot=12
IsNot=12,
NoLike = 13,
}
}

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -100,7 +100,7 @@ namespace SqlSugar
public static TResult AggregateAvg<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static int AggregateCount(int thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult MappingColumn<TResult>(TResult oldColumnName,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
/// <summary>
///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.*

7
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs

@ -346,6 +346,9 @@ namespace SqlSugar
}
string temp = " {0} {1} {2} {3} ";
string parameterName = string.Format("{0}Conditional{1}{2}", sqlBuilder.SqlParameterKeyWord, item.FieldName, index);
if (parameterName.Contains(".")) {
parameterName = parameterName.Replace(".", "_");
}
switch (item.ConditionalType)
{
case ConditionalType.Equal:
@ -388,6 +391,10 @@ namespace SqlSugar
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "LIKE", parameterName);
parameters.Add(new SugarParameter(parameterName, item.FieldValue + "%"));
break;
case ConditionalType.NoLike:
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), " NOT LIKE", parameterName);
parameters.Add(new SugarParameter(parameterName, item.FieldValue + "%"));
break;
case ConditionalType.LikeRight:
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "LIKE", parameterName);
parameters.Add(new SugarParameter(parameterName, "%" + item.FieldValue));

3
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlBuilder.cs

@ -35,7 +35,10 @@ namespace SqlSugar
string GetNoTranslationColumnName(string name);
string GetPackTable(string sql,string shortName);
string GetDefaultShortName();
string GetWhere(string fieldName, string conditionalType, int? parameterIndex = null);
string GetUnionAllSql(List<string> sqlList);
string GetUnionSql(List<string> sqlList);
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
}
}

9
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs

@ -18,6 +18,15 @@ namespace SqlSugar
IUpdateable<T> With(string lockString);
IUpdateable<T> Where(bool isNoUpdateNull,bool IsOffIdentity = false);
IUpdateable<T> Where(Expression<Func<T, bool>> expression);
IUpdateable<T> Where(string whereSql,object parameters=null);
/// <summary>
///
/// </summary>
/// <param name="fieldName"></param>
/// <param name="conditionalType">for example : = </param>
/// <param name="fieldValue"></param>
/// <returns></returns>
IUpdateable<T> Where(string fieldName, string conditionalType, object fieldValue);
/// <summary>
/// Non primary key entity update function
/// </summary>

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs

@ -16,6 +16,8 @@ namespace SqlSugar
{
foreach (var item in entityInfo.Columns)
{
if (item.IsIgnore)
continue;
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
columns.Add(dbColumnInfo);
}
@ -35,7 +37,8 @@ namespace SqlSugar
IsNullable = item.IsNullable,
DefaultValue = item.DefaultValue,
ColumnDescription = item.ColumnDescription,
Length = item.Length
Length = item.Length,
DecimalDigits=item.DecimalDigits
};
GetDbType(item, propertyType, result);
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

@ -70,6 +70,7 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("longblob",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),

39
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

@ -185,7 +185,7 @@ namespace SqlSugar
{
foreach (var item in columns)
{
if (item.DbColumnName.Equals("GUID", StringComparison.CurrentCultureIgnoreCase) && item.Length == 0)
if (item.DbColumnName.Equals("GUID",StringComparison.CurrentCultureIgnoreCase)&&item.Length==0)
{
item.Length = 10;
}
@ -193,9 +193,8 @@ namespace SqlSugar
}
string sql = GetCreateTableSql(tableName, columns);
string primaryKeyInfo = null;
if (columns.Any(it => it.IsPrimarykey) && isCreatePrimaryKey)
{
primaryKeyInfo = string.Format(", Primary key({0})", string.Join(",", columns.Where(it => it.IsPrimarykey).Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
if (columns.Any(it => it.IsPrimarykey)&&isCreatePrimaryKey) {
primaryKeyInfo =string.Format( ", Primary key({0})",string.Join(",",columns.Where(it=>it.IsPrimarykey).Select(it=>this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
}
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
@ -209,11 +208,9 @@ namespace SqlSugar
foreach (var item in columns)
{
string columnName = item.DbColumnName;
string dataSize = "";
dataSize = GetSize(item);
string dataType = item.DataType;
if (dataType == "varchar"&& item.Length==0) {
item.Length = 1;
}
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
@ -223,6 +220,32 @@ namespace SqlSugar
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
return tableString;
}
protected override string GetSize(DbColumnInfo item)
{
string dataSize = null;
var isMax = item.Length > 4000 || item.Length == -1;
if (isMax)
{
dataSize="";
item.DataType = "longtext";
}
else if (item.Length > 0 && item.DecimalDigits == 0)
{
dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
}
else if (item.Length == 0 && item.DecimalDigits > 0)
{
item.Length = 10;
dataSize = string.Format("({0},{1})", item.Length, item.DecimalDigits);
}
else if (item.Length > 0 && item.DecimalDigits > 0)
{
dataSize = item.Length > 0 ? string.Format("({0},{1})", item.Length, item.DecimalDigits) : null;
}
return dataSize;
}
public override bool IsAnyConstraint(string constraintName)
{
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs

@ -116,7 +116,7 @@ namespace SqlSugar
sqlParameter.Direction = ParameterDirection.Input;
}
result[index] = sqlParameter;
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput))
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue))
{
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);

7
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -45,6 +45,13 @@ namespace SqlSugar
var parameter = model.Args[0];
return string.Format(" to_timestamp({0},'0000-01-01 hh24:mi:ss') ", parameter.MemberName);
}
public override string Substring(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
return string.Format("SUBSTR({0},1 + {1},{2})", parameter.MemberName, parameter2.MemberName, parameter3.MemberName);
}
public override string DateValue(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs

@ -98,7 +98,7 @@ namespace SqlSugar
sqlParameter.DbType = parameter.DbType;
sqlParameter.Direction = parameter.Direction;
result[index] = sqlParameter;
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput))
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput,ParameterDirection.ReturnValue))
{
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs

@ -94,7 +94,7 @@ namespace SqlSugar
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = parameter.DbType;
result[index] = sqlParameter;
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput))
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput,ParameterDirection.ReturnValue))
{
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);

70
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs

@ -28,14 +28,25 @@ namespace SqlSugar
{
return Context.Queryable<T>().ToList();
}
public T GetSingle<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return Context.Queryable<T>().Single(whereExpression);
}
public List<T> GetList<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return Context.Queryable<T>().Where(whereExpression).ToList();
}
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression,PageModel page) where T : class, new()
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression, PageModel page) where T : class, new()
{
int count = 0;
var result= Context.Queryable<T>().Where(whereExpression).ToPageList(page.PageIndex,page.PageSize,ref count);
var result = Context.Queryable<T>().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new()
{
int count = 0;
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
@ -46,6 +57,13 @@ namespace SqlSugar
page.PageCount = count;
return result;
}
public List<T> GetPageList<T>(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new()
{
int count = 0;
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
public bool IsAny<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return Context.Queryable<T>().Where(whereExpression).Any();
@ -70,6 +88,10 @@ namespace SqlSugar
{
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
}
public bool UpdateRange<T>(T[] updateObjs) where T : class, new()
{
return this.Context.Updateable(updateObjs).ExecuteCommand() > 0;
}
public bool Update<T>(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression) where T : class, new()
{
return this.Context.Updateable<T>().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0;
@ -109,7 +131,7 @@ namespace SqlSugar
{
return Context.Queryable<T>().InSingle(id);
}
public List<T> GetList()
public List<T> GetList()
{
return Context.Queryable<T>().ToList();
}
@ -117,6 +139,10 @@ namespace SqlSugar
{
return Context.Queryable<T>().Where(whereExpression).ToList();
}
public T GetSingle(Expression<Func<T, bool>> whereExpression)
{
return Context.Queryable<T>().Single(whereExpression);
}
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page)
{
int count = 0;
@ -124,6 +150,13 @@ namespace SqlSugar
page.PageCount = count;
return result;
}
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
int count = 0;
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
public List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page)
{
int count = 0;
@ -131,19 +164,32 @@ namespace SqlSugar
page.PageCount = count;
return result;
}
public List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
int count = 0;
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count);
page.PageCount = count;
return result;
}
public bool IsAny(Expression<Func<T, bool>> whereExpression)
{
return Context.Queryable<T>().Where(whereExpression).Any();
}
public bool Insert(T insertObj)
public int Count(Expression<Func<T, bool>> whereExpression)
{
return Context.Queryable<T>().Where(whereExpression).Count();
}
public bool Insert(T insertObj)
{
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
}
public int InsertReturnIdentity(T insertObj)
public int InsertReturnIdentity(T insertObj)
{
return this.Context.Insertable(insertObj).ExecuteReturnIdentity();
}
public bool InsertRange(T[] insertObjs)
public bool InsertRange(T[] insertObjs)
{
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
}
@ -151,11 +197,15 @@ namespace SqlSugar
{
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
}
public bool Update(T updateObj)
public bool Update(T updateObj)
{
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
}
public bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
public bool UpdateRange(T [] updateObjs)
{
return this.Context.Updateable(updateObjs).ExecuteCommand() > 0;
}
public bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
{
return this.Context.Updateable<T>().UpdateColumns(columns).Where(whereExpression).ExecuteCommand() > 0;
}
@ -163,11 +213,11 @@ namespace SqlSugar
{
return this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommand() > 0;
}
public bool Delete(Expression<Func<T, bool>> whereExpression)
public bool Delete(Expression<Func<T, bool>> whereExpression)
{
return this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommand() > 0;
}
public bool DeleteById(dynamic id)
public bool DeleteById(dynamic id)
{
return this.Context.Deleteable<T>().In(id).ExecuteCommand() > 0;
}

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.6.4.7</Version>
<Version>4.6.4.9</Version>
<Copyright>sun_kai_xuan</Copyright>
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>

34
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs

@ -38,7 +38,7 @@ namespace SqlSugar
DependencyManagement.TryOracle();
break;
case DbType.PostgreSQL:
throw new Exception("Development 50%");
throw new Exception("开发中");
default:
throw new Exception("ConnectionConfig.DbType is null");
}
@ -395,6 +395,34 @@ namespace SqlSugar
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
return UnionAll(queryables.ToArray());
}
public virtual ISugarQueryable<T> Union<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
{
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
int i = 1;
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
foreach (var item in queryables)
{
var sqlObj = item.ToSql();
string sql = sqlObj.Key;
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i);
if (sqlObj.Value.HasValue())
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
else
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, new List<SugarParameter>()));
i++;
}
var allSql = sqlBuilder.GetUnionSql(allItems.Select(it => it.Key).ToList());
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
var resulut = this.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable")).With(SqlWith.Null);
resulut.AddParameters(allParameters);
return resulut.Select<T>(sqlBuilder.SqlSelectAll);
}
public virtual ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
{
Check.Exception(queryables.IsNullOrEmpty(), "Union.queryables is null ");
return Union(queryables.ToArray());
}
#endregion
#region SqlQueryable
@ -626,7 +654,9 @@ namespace SqlSugar
}
public virtual SimpleClient GetSimpleClient()
{
return this.SimpleClient;
if (this.Context._SimpleClient == null)
this.Context._SimpleClient = new SimpleClient(this.Context);
return this.Context._SimpleClient;
}
#endregion

11
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

@ -17,6 +17,17 @@ namespace SqlSugar
return type==null ? oldType : type;
}
internal static Type GetRootBaseType(Type entityType)
{
var baseType = entityType.BaseType;
while (baseType != null && baseType.BaseType != UtilConstants.ObjType)
{
baseType = baseType.BaseType;
}
return baseType;
}
internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable)
{
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);

BIN
Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.
Loading…
Cancel
Save