mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Update Core
This commit is contained in:
@@ -863,6 +863,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result = GetData<T>(typeof(T), dataReader);
|
result = GetData<T>(typeof(T), dataReader);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataReader.Read();
|
||||||
|
}
|
||||||
List<T2> result2 = null;
|
List<T2> result2 = null;
|
||||||
if (NextResult(dataReader))
|
if (NextResult(dataReader))
|
||||||
{
|
{
|
||||||
|
@@ -144,6 +144,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField.ToUpper(), entityValue);
|
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField.ToUpper(), entityValue);
|
||||||
}
|
}
|
||||||
|
else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL&& (this.Context.CurrentConnectionConfig.MoreSettings==null||this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower==true))
|
||||||
|
{
|
||||||
|
andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);
|
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);
|
||||||
|
@@ -336,6 +336,10 @@ namespace SqlSugar
|
|||||||
var exp=field.GetValue(item,null) as Expression;
|
var exp=field.GetValue(item,null) as Expression;
|
||||||
var isMain = ChildType == this.EntityType;
|
var isMain = ChildType == this.EntityType;
|
||||||
var isSingle = IsSingle();
|
var isSingle = IsSingle();
|
||||||
|
if (ChildType != this.EntityType&&isSingle)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
var expValue = GetExpressionValue(exp, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
var expValue = GetExpressionValue(exp, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
||||||
var sql = expValue.GetResultString();
|
var sql = expValue.GetResultString();
|
||||||
var itName = (exp as LambdaExpression).Parameters[0].Name;
|
var itName = (exp as LambdaExpression).Parameters[0].Name;
|
||||||
@@ -350,10 +354,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (isSingle)
|
if (isSingle)
|
||||||
{
|
{
|
||||||
if (ChildType != this.EntityType)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (isMain)
|
else if (isMain)
|
||||||
{
|
{
|
||||||
|
@@ -257,11 +257,14 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (PrimaryKeys.HasValue())
|
else if (PrimaryKeys.HasValue())
|
||||||
{
|
{
|
||||||
foreach (var item in PrimaryKeys)
|
if (IsWhereColumns == false)
|
||||||
{
|
{
|
||||||
var isFirst = whereString == null;
|
foreach (var item in PrimaryKeys)
|
||||||
whereString += (isFirst ? " WHERE " : " AND ");
|
{
|
||||||
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
var isFirst = whereString == null;
|
||||||
|
whereString += (isFirst ? " WHERE " : " AND ");
|
||||||
|
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PrimaryKeys.HasValue()&&IsWhereColumns)
|
if (PrimaryKeys.HasValue()&&IsWhereColumns)
|
||||||
|
@@ -14,6 +14,6 @@ namespace SqlSugar
|
|||||||
PostgreSQL,
|
PostgreSQL,
|
||||||
Dm,
|
Dm,
|
||||||
Kdbndp,
|
Kdbndp,
|
||||||
Oscar
|
Oscar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -542,7 +542,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (types.Count == i)
|
if (types.Count == i&&(types.Count==types.Distinct().Count()))
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -292,6 +292,14 @@ namespace SqlSugar
|
|||||||
break;
|
break;
|
||||||
case ResolveExpressType.FieldSingle:
|
case ResolveExpressType.FieldSingle:
|
||||||
case ResolveExpressType.FieldMultiple:
|
case ResolveExpressType.FieldMultiple:
|
||||||
|
if (express.Method.Name == "ToString" && express.Object!=null&&express.Object?.Type == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
var format = (args[0] as ConstantExpression).Value+"";
|
||||||
|
var value = GetNewExpressionValue(express.Object);
|
||||||
|
var dateString = GeDateFormat(format, value);
|
||||||
|
base.AppendValue(parameter, isLeft, dateString);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -55,8 +55,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (Regex.IsMatch(result, regex))
|
if (Regex.IsMatch(result, regex))
|
||||||
{
|
{
|
||||||
result = "AND " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
var value = GetValue(result, regex);
|
||||||
return result;
|
if (value is Expression)
|
||||||
|
{
|
||||||
|
var p = this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value);
|
||||||
|
result = "AND " + SubTools.GetMethodValue(Context, value as Expression, ResolveExpressType.WhereMultiple);
|
||||||
|
argExp = value as Expression;
|
||||||
|
this.Context.Parameters.Remove(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = "AND " + value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
@@ -64,5 +75,10 @@ namespace SqlSugar
|
|||||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object GetValue(string result, string regex)
|
||||||
|
{
|
||||||
|
return this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubHaving : ISubOperation
|
||||||
|
{
|
||||||
|
public bool HasWhere
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "Having"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 480;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var argExp = exp.Arguments[0];
|
||||||
|
var result = "Having " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
|
||||||
|
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
|
if (this.Context.JoinIndex == 0)
|
||||||
|
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -55,8 +55,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (Regex.IsMatch(result, regex))
|
if (Regex.IsMatch(result, regex))
|
||||||
{
|
{
|
||||||
result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
var value = GetValue(result, regex);
|
||||||
return result;
|
if (value is Expression)
|
||||||
|
{
|
||||||
|
var p = this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value);
|
||||||
|
result = "WHERE " + SubTools.GetMethodValue(Context, value as Expression, ResolveExpressType.WhereMultiple);
|
||||||
|
argExp = value as Expression;
|
||||||
|
this.Context.Parameters.Remove(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = "WHERE " + value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
@@ -64,5 +75,10 @@ namespace SqlSugar
|
|||||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object GetValue(string result, string regex)
|
||||||
|
{
|
||||||
|
return this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,8 @@ namespace SqlSugar
|
|||||||
new SubOrderBy(){ Context=Context },
|
new SubOrderBy(){ Context=Context },
|
||||||
new SubOrderByDesc(){ Context=Context },
|
new SubOrderByDesc(){ Context=Context },
|
||||||
new SubGroupBy(){ Context=Context},
|
new SubGroupBy(){ Context=Context},
|
||||||
new SubAs(){Context=Context}
|
new SubAs(){Context=Context},
|
||||||
|
new SubHaving(){ Context=Context}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,10 +27,18 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public Subqueryable<T> Where(Expression exp)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public Subqueryable<T> Where(Func<T, bool> expression)
|
public Subqueryable<T> Where(Func<T, bool> expression)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public Subqueryable<T> Having(Func<T, bool> expression)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public Subqueryable<T> Where<Main, Join1>(Func<Main, Join1, bool> expression)
|
public Subqueryable<T> Where<Main, Join1>(Func<Main, Join1, bool> expression)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
|
@@ -408,7 +408,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var key = typeName + "." + name;
|
var key = typeName + "." + name;
|
||||||
var info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
|
var info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
|
||||||
if (mappingKeys.ContainsKey(item.Name))
|
if (mappingKeys!=null&&mappingKeys.ContainsKey(item.Name))
|
||||||
{
|
{
|
||||||
key = mappingKeys[item.Name]+"."+typeName + "." + name;
|
key = mappingKeys[item.Name]+"."+typeName + "." + name;
|
||||||
info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
|
info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
|
||||||
|
@@ -83,6 +83,7 @@ namespace SqlSugar
|
|||||||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
||||||
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
|
||||||
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@short),
|
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@short),
|
||||||
|
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
|
||||||
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
|
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
|
||||||
new KeyValuePair<string, CSharpDataType>("interval year to month",CSharpDataType.@int),
|
new KeyValuePair<string, CSharpDataType>("interval year to month",CSharpDataType.@int),
|
||||||
new KeyValuePair<string, CSharpDataType>("interval day to second",CSharpDataType.@int),
|
new KeyValuePair<string, CSharpDataType>("interval day to second",CSharpDataType.@int),
|
||||||
|
@@ -25,13 +25,13 @@ namespace SqlSugar
|
|||||||
this.Builder = builder;
|
this.Builder = builder;
|
||||||
this.Entitys = entitys;
|
this.Entitys = entitys;
|
||||||
}
|
}
|
||||||
public bool ExecuteBlukCopy(string characterSet)
|
public bool ExecuteBulkCopy(string characterSet)
|
||||||
{
|
{
|
||||||
this.Chara = characterSet;
|
this.Chara = characterSet;
|
||||||
return ExecuteBlukCopy();
|
return ExecuteBulkCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ExecuteBlukCopy()
|
public bool ExecuteBulkCopy()
|
||||||
{
|
{
|
||||||
var IsBulkLoad = false;
|
var IsBulkLoad = false;
|
||||||
if (Entitys == null || Entitys.Length <= 0)
|
if (Entitys == null || Entitys.Length <= 0)
|
||||||
@@ -42,6 +42,10 @@ namespace SqlSugar
|
|||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||||
dt.TableName = this.Builder.GetTranslationColumnName(entity.DbTableName);
|
dt.TableName = this.Builder.GetTranslationColumnName(entity.DbTableName);
|
||||||
|
if (this.Context.MappingTables != null && this.Context.MappingTables.Any(it => it.EntityName == it.EntityName))
|
||||||
|
{
|
||||||
|
dt.TableName = this.Builder.GetTranslationColumnName(this.Context.MappingTables.First(it => it.EntityName == it.EntityName).DbTableName);
|
||||||
|
}
|
||||||
//创建属性的集合
|
//创建属性的集合
|
||||||
List<PropertyInfo> pList = new List<PropertyInfo>();
|
List<PropertyInfo> pList = new List<PropertyInfo>();
|
||||||
//把所有的public属性加入到集合 并添加DataTable的列
|
//把所有的public属性加入到集合 并添加DataTable的列
|
||||||
@@ -111,15 +115,15 @@ namespace SqlSugar
|
|||||||
return IsBulkLoad; ;
|
return IsBulkLoad; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> ExecuteBlukCopyAsync()
|
public Task<bool> ExecuteBulkCopyAsync()
|
||||||
{
|
{
|
||||||
return Task.FromResult(ExecuteBlukCopy());
|
return Task.FromResult(ExecuteBulkCopy());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> ExecuteBlukCopyAsync(string characterSet)
|
public Task<bool> ExecuteBulkCopyAsync(string characterSet)
|
||||||
{
|
{
|
||||||
this.Chara = characterSet;
|
this.Chara = characterSet;
|
||||||
return Task.FromResult(ExecuteBlukCopy());
|
return Task.FromResult(ExecuteBulkCopy());
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
|
@@ -66,7 +66,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
private string ToCountSqlString()
|
private string ToCountSqlString()
|
||||||
{
|
{
|
||||||
base.AppendFilter();
|
//base.AppendFilter();
|
||||||
string oldOrderValue = this.OrderByValue;
|
string oldOrderValue = this.OrderByValue;
|
||||||
string result = null;
|
string result = null;
|
||||||
sql = new StringBuilder();
|
sql = new StringBuilder();
|
||||||
|
@@ -101,6 +101,35 @@ namespace SqlSugar
|
|||||||
return propertyName.ToLower(isAutoToLower);
|
return propertyName.ToLower(isAutoToLower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetValue(object entityValue)
|
||||||
|
{
|
||||||
|
if (entityValue == null)
|
||||||
|
return null;
|
||||||
|
var type = UtilMethods.GetUnderType(entityValue.GetType());
|
||||||
|
if (UtilConstants.NumericalTypes.Contains(type))
|
||||||
|
{
|
||||||
|
return entityValue.ToString();
|
||||||
|
}
|
||||||
|
else if (type == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
return this.DbMehtods.ToDate(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Args = new System.Collections.Generic.List<MethodCallExpressionArgs>() {
|
||||||
|
new MethodCallExpressionArgs(){ MemberName=$"'{entityValue}'" }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.DbMehtods.ToString(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Args = new System.Collections.Generic.List<MethodCallExpressionArgs>() {
|
||||||
|
new MethodCallExpressionArgs(){ MemberName=$"'{entityValue}'" }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
|
public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
@@ -140,7 +169,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (parameter2.MemberValue.ObjToString() == DateType.Minute.ToString())
|
if (parameter2.MemberValue.ObjToString() == DateType.Minute.ToString())
|
||||||
{
|
{
|
||||||
format = "mm";
|
format = "mi";
|
||||||
}
|
}
|
||||||
if (parameter2.MemberValue.ObjToString() == DateType.Second.ToString())
|
if (parameter2.MemberValue.ObjToString() == DateType.Second.ToString())
|
||||||
{
|
{
|
||||||
@@ -148,7 +177,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (parameter2.MemberValue.ObjToString() == DateType.Millisecond.ToString())
|
if (parameter2.MemberValue.ObjToString() == DateType.Millisecond.ToString())
|
||||||
{
|
{
|
||||||
format = "ss";
|
format = "ms";
|
||||||
}
|
}
|
||||||
return string.Format(" cast( to_char({1},'{0}')as integer ) ", format, parameter.MemberName);
|
return string.Format(" cast( to_char({1},'{0}')as integer ) ", format, parameter.MemberName);
|
||||||
}
|
}
|
||||||
|
@@ -166,7 +166,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public static bool IsClass(this Type thisValue)
|
public static bool IsClass(this Type thisValue)
|
||||||
{
|
{
|
||||||
return thisValue != StringType && thisValue.IsEntity();
|
return thisValue != StringType && thisValue.IsEntity()&&thisValue!=UtilConstants.ByteArrayType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user