mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update core
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -243,7 +244,16 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
insertDictionary.Add(item.DbColumnName, item.PropertyInfo.GetValue(insetObject));
|
var value = item.PropertyInfo.GetValue(insetObject);
|
||||||
|
if (value == null&&this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL)
|
||||||
|
{
|
||||||
|
var underType= UtilMethods.GetUnderType(item.PropertyInfo.PropertyType);
|
||||||
|
if (underType == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
value = SqlDateTime.Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertDictionary.Add(item.DbColumnName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return insertDictionary;
|
return insertDictionary;
|
||||||
|
@@ -331,36 +331,30 @@ namespace SqlSugar
|
|||||||
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
|
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||||
Type type = item.GetType();
|
Type type = item.GetType();
|
||||||
PropertyInfo field = type.GetProperty("exp", flag);
|
PropertyInfo field = type.GetProperty("exp", flag);
|
||||||
Type ChildType = type.GetProperty("type", flag).GetValue(item,null) as Type;
|
Type ChildType = type.GetProperty("type", flag).GetValue(item, null) as Type;
|
||||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(ChildType);
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(ChildType);
|
||||||
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 sql = expValue.GetResultString();
|
|
||||||
var itName = (exp as LambdaExpression).Parameters[0].Name;
|
var itName = (exp as LambdaExpression).Parameters[0].Name;
|
||||||
itName = this.Builder.GetTranslationColumnName(itName) + ".";
|
itName = this.Builder.GetTranslationColumnName(itName) + ".";
|
||||||
var isEasyJoin = this.EasyJoinInfos.Count > 0;
|
var isEasyJoin = this.EasyJoinInfos.Count > 0;
|
||||||
if (WhereInfos.Count == 0)
|
|
||||||
{
|
string sql = "";
|
||||||
sql =( " WHERE " + sql);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
sql = (" AND " + sql);
|
|
||||||
}
|
|
||||||
if (isSingle)
|
if (isSingle)
|
||||||
{
|
{
|
||||||
|
if (ChildType != this.EntityType && isSingle)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sql = GetSql(exp, isSingle);
|
||||||
}
|
}
|
||||||
else if (isMain)
|
else if (isMain)
|
||||||
{
|
{
|
||||||
if (TableShortName == null)
|
if (TableShortName == null)
|
||||||
return;
|
return;
|
||||||
var shortName = this.Builder.GetTranslationColumnName(TableShortName) + ".";
|
var shortName = this.Builder.GetTranslationColumnName(TableShortName) + ".";
|
||||||
|
sql = GetSql(exp, isSingle);
|
||||||
sql = sql.Replace(itName, shortName);
|
sql = sql.Replace(itName, shortName);
|
||||||
}
|
}
|
||||||
else if (isEasyJoin)
|
else if (isEasyJoin)
|
||||||
@@ -368,11 +362,12 @@ namespace SqlSugar
|
|||||||
var easyInfo = EasyJoinInfos.FirstOrDefault(it =>
|
var easyInfo = EasyJoinInfos.FirstOrDefault(it =>
|
||||||
it.Value.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
|
it.Value.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
|
||||||
it.Value.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
|
it.Value.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
|
||||||
if (easyInfo.Key==null)
|
if (easyInfo.Key == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var shortName = this.Builder.GetTranslationColumnName(easyInfo.Key.Trim()) + ".";
|
var shortName = this.Builder.GetTranslationColumnName(easyInfo.Key.Trim()) + ".";
|
||||||
|
sql = GetSql(exp, isSingle);
|
||||||
sql = sql.Replace(itName, shortName);
|
sql = sql.Replace(itName, shortName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -385,11 +380,28 @@ namespace SqlSugar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var shortName = this.Builder.GetTranslationColumnName(easyInfo.ShortName.Trim()) + ".";
|
var shortName = this.Builder.GetTranslationColumnName(easyInfo.ShortName.Trim()) + ".";
|
||||||
|
sql = GetSql(exp, isSingle);
|
||||||
sql = sql.Replace(itName, shortName);
|
sql = sql.Replace(itName, shortName);
|
||||||
}
|
}
|
||||||
WhereInfos.Add(sql);
|
WhereInfos.Add(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetSql(Expression exp, bool isSingle)
|
||||||
|
{
|
||||||
|
var expValue = GetExpressionValue(exp, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
||||||
|
var sql = expValue.GetResultString();
|
||||||
|
if (WhereInfos.Count == 0)
|
||||||
|
{
|
||||||
|
sql = (" WHERE " + sql);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = (" AND " + sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string GetExternalOrderBy(string externalOrderBy)
|
public virtual string GetExternalOrderBy(string externalOrderBy)
|
||||||
{
|
{
|
||||||
return Regex.Replace(externalOrderBy, @"\[\w+\]\.", "");
|
return Regex.Replace(externalOrderBy, @"\[\w+\]\.", "");
|
||||||
|
@@ -90,6 +90,11 @@ namespace SqlSugar
|
|||||||
foreach (var parameter in parameters)
|
foreach (var parameter in parameters)
|
||||||
{
|
{
|
||||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||||
|
if(parameter.Value is System.Data.SqlTypes.SqlDateTime&¶meter.DbType==System.Data.DbType.AnsiString)
|
||||||
|
{
|
||||||
|
parameter.DbType = System.Data.DbType.DateTime;
|
||||||
|
parameter.Value = DBNull.Value;
|
||||||
|
}
|
||||||
var sqlParameter = new NpgsqlParameter();
|
var sqlParameter = new NpgsqlParameter();
|
||||||
sqlParameter.ParameterName = parameter.ParameterName;
|
sqlParameter.ParameterName = parameter.ParameterName;
|
||||||
sqlParameter.Size = parameter.Size;
|
sqlParameter.Size = parameter.Size;
|
||||||
|
Reference in New Issue
Block a user