mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update Core
This commit is contained in:
parent
ed409e6878
commit
3e8ff391cf
@ -863,6 +863,10 @@ namespace SqlSugar
|
||||
{
|
||||
result = GetData<T>(typeof(T), dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataReader.Read();
|
||||
}
|
||||
List<T2> result2 = null;
|
||||
if (NextResult(dataReader))
|
||||
{
|
||||
|
@ -144,6 +144,10 @@ namespace SqlSugar
|
||||
{
|
||||
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
|
||||
{
|
||||
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);
|
||||
|
@ -336,6 +336,10 @@ namespace SqlSugar
|
||||
var exp=field.GetValue(item,null) as Expression;
|
||||
var isMain = ChildType == this.EntityType;
|
||||
var isSingle = IsSingle();
|
||||
if (ChildType != this.EntityType&&isSingle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var expValue = GetExpressionValue(exp, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
||||
var sql = expValue.GetResultString();
|
||||
var itName = (exp as LambdaExpression).Parameters[0].Name;
|
||||
@ -350,10 +354,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (isSingle)
|
||||
{
|
||||
if (ChildType != this.EntityType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else if (isMain)
|
||||
{
|
||||
|
@ -257,11 +257,14 @@ namespace SqlSugar
|
||||
}
|
||||
else if (PrimaryKeys.HasValue())
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
if (IsWhereColumns == false)
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? " WHERE " : " AND ");
|
||||
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? " WHERE " : " AND ");
|
||||
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PrimaryKeys.HasValue()&&IsWhereColumns)
|
||||
|
@ -14,6 +14,6 @@ namespace SqlSugar
|
||||
PostgreSQL,
|
||||
Dm,
|
||||
Kdbndp,
|
||||
Oscar
|
||||
Oscar
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
if (types.Count == i)
|
||||
if (types.Count == i&&(types.Count==types.Distinct().Count()))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -292,6 +292,14 @@ namespace SqlSugar
|
||||
break;
|
||||
case ResolveExpressType.FieldSingle:
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
@ -55,8 +55,19 @@ namespace SqlSugar
|
||||
}
|
||||
if (Regex.IsMatch(result, regex))
|
||||
{
|
||||
result = "AND " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
||||
return result;
|
||||
var value = GetValue(result, regex);
|
||||
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;
|
||||
@ -64,5 +75,10 @@ namespace SqlSugar
|
||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||
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))
|
||||
{
|
||||
result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
|
||||
return result;
|
||||
var value = GetValue(result, regex);
|
||||
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;
|
||||
@ -64,5 +75,10 @@ namespace SqlSugar
|
||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||
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 SubOrderByDesc(){ 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;
|
||||
}
|
||||
public Subqueryable<T> Where(Expression exp)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public Subqueryable<T> Where(Func<T, bool> expression)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public Subqueryable<T> Having(Func<T, bool> expression)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public Subqueryable<T> Where<Main, Join1>(Func<Main, Join1, bool> expression)
|
||||
{
|
||||
return this;
|
||||
|
@ -408,7 +408,7 @@ namespace SqlSugar
|
||||
{
|
||||
var key = typeName + "." + name;
|
||||
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;
|
||||
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>("bigint",CSharpDataType.@long),
|
||||
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>("interval year to month",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("interval day to second",CSharpDataType.@int),
|
||||
|
@ -25,13 +25,13 @@ namespace SqlSugar
|
||||
this.Builder = builder;
|
||||
this.Entitys = entitys;
|
||||
}
|
||||
public bool ExecuteBlukCopy(string characterSet)
|
||||
public bool ExecuteBulkCopy(string characterSet)
|
||||
{
|
||||
this.Chara = characterSet;
|
||||
return ExecuteBlukCopy();
|
||||
return ExecuteBulkCopy();
|
||||
}
|
||||
|
||||
public bool ExecuteBlukCopy()
|
||||
public bool ExecuteBulkCopy()
|
||||
{
|
||||
var IsBulkLoad = false;
|
||||
if (Entitys == null || Entitys.Length <= 0)
|
||||
@ -42,6 +42,10 @@ namespace SqlSugar
|
||||
Type type = typeof(T);
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
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>();
|
||||
//把所有的public属性加入到集合 并添加DataTable的列
|
||||
@ -111,15 +115,15 @@ namespace SqlSugar
|
||||
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;
|
||||
return Task.FromResult(ExecuteBlukCopy());
|
||||
return Task.FromResult(ExecuteBulkCopy());
|
||||
}
|
||||
|
||||
#region Helper
|
||||
|
@ -66,7 +66,7 @@ namespace SqlSugar
|
||||
}
|
||||
private string ToCountSqlString()
|
||||
{
|
||||
base.AppendFilter();
|
||||
//base.AppendFilter();
|
||||
string oldOrderValue = this.OrderByValue;
|
||||
string result = null;
|
||||
sql = new StringBuilder();
|
||||
|
@ -101,6 +101,35 @@ namespace SqlSugar
|
||||
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
|
||||
{
|
||||
@ -140,7 +169,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (parameter2.MemberValue.ObjToString() == DateType.Minute.ToString())
|
||||
{
|
||||
format = "mm";
|
||||
format = "mi";
|
||||
}
|
||||
if (parameter2.MemberValue.ObjToString() == DateType.Second.ToString())
|
||||
{
|
||||
@ -148,7 +177,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (parameter2.MemberValue.ObjToString() == DateType.Millisecond.ToString())
|
||||
{
|
||||
format = "ss";
|
||||
format = "ms";
|
||||
}
|
||||
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)
|
||||
{
|
||||
return thisValue != StringType && thisValue.IsEntity();
|
||||
return thisValue != StringType && thisValue.IsEntity()&&thisValue!=UtilConstants.ByteArrayType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user