mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-01 10:10:16 +08:00
Update Core
This commit is contained in:
parent
6352e499dd
commit
6d5518f656
@ -6,6 +6,7 @@ using System.Data;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@ -41,6 +42,7 @@ namespace SqlSugar
|
|||||||
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
|
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
|
||||||
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
||||||
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
||||||
|
private static readonly MethodInfo getXelement = typeof(IDataRecordExtensions).GetMethod("GetXelement");
|
||||||
private static readonly MethodInfo getConvertStringGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertStringGuid");
|
private static readonly MethodInfo getConvertStringGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertStringGuid");
|
||||||
private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
|
private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
|
||||||
private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
|
private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
|
||||||
@ -182,6 +184,21 @@ namespace SqlSugar
|
|||||||
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||||
generator.MarkLabel(endIfLabel);
|
generator.MarkLabel(endIfLabel);
|
||||||
}
|
}
|
||||||
|
else if (columnInfo.UnderType == typeof(XElement))
|
||||||
|
{
|
||||||
|
int i = DataRecord.GetOrdinal(fieldName);
|
||||||
|
Label endIfLabel = generator.DefineLabel();
|
||||||
|
generator.Emit(OpCodes.Ldarg_0);
|
||||||
|
generator.Emit(OpCodes.Ldc_I4, i);
|
||||||
|
generator.Emit(OpCodes.Callvirt, isDBNullMethod);
|
||||||
|
generator.Emit(OpCodes.Brtrue, endIfLabel);
|
||||||
|
generator.Emit(OpCodes.Ldloc, result);
|
||||||
|
generator.Emit(OpCodes.Ldarg_0);
|
||||||
|
generator.Emit(OpCodes.Ldc_I4, i);
|
||||||
|
BindMethod(generator, columnInfo, i);
|
||||||
|
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||||
|
generator.MarkLabel(endIfLabel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void BindField(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
|
private void BindField(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
|
||||||
{
|
{
|
||||||
@ -285,6 +302,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
method = isNullableType ? getConvertStringGuid : getStringGuid;
|
method = isNullableType ? getConvertStringGuid : getStringGuid;
|
||||||
}
|
}
|
||||||
|
else if (bindProperyTypeName == "xelement")
|
||||||
|
{
|
||||||
|
method = getXelement;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CSharpDataType.DateTime:
|
case CSharpDataType.DateTime:
|
||||||
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
|
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||||
|
@ -3,12 +3,19 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public static partial class IDataRecordExtensions
|
public static partial class IDataRecordExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
#region Common Extensions
|
#region Common Extensions
|
||||||
|
public static XElement GetXelement(this IDataRecord dr, int i)
|
||||||
|
{
|
||||||
|
var result = XElement.Parse(dr.GetString(i).ToString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
public static Guid GetStringGuid(this IDataRecord dr, int i)
|
public static Guid GetStringGuid(this IDataRecord dr, int i)
|
||||||
{
|
{
|
||||||
var result = Guid.Parse(dr.GetValue(i).ToString());
|
var result = Guid.Parse(dr.GetValue(i).ToString());
|
||||||
|
@ -306,7 +306,11 @@ namespace SqlSugar
|
|||||||
var queryable = this.Context.Queryable<T>();
|
var queryable = this.Context.Queryable<T>();
|
||||||
queryable.QueryBuilder.LambdaExpressions.ParameterIndex= 1000;
|
queryable.QueryBuilder.LambdaExpressions.ParameterIndex= 1000;
|
||||||
var sqlable= queryable.ToSql();
|
var sqlable= queryable.ToSql();
|
||||||
this.Where(Regex.Split(sqlable.Key," Where ",RegexOptions.IgnoreCase).Last(), sqlable.Value);
|
var whereInfos = Regex.Split(sqlable.Key, " Where ", RegexOptions.IgnoreCase);
|
||||||
|
if (whereInfos.Length > 1)
|
||||||
|
{
|
||||||
|
this.Where(whereInfos.Last(), sqlable.Value);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public SplitTableDeleteProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc)
|
public SplitTableDeleteProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc)
|
||||||
|
@ -24,7 +24,9 @@ namespace SqlSugar
|
|||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result += this.Context.Updateable(addList).IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommand();
|
result += this.Context.Updateable(addList)
|
||||||
|
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity,this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||||
|
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommand();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -38,7 +40,9 @@ namespace SqlSugar
|
|||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result += await this.Context.Updateable(addList).IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandAsync();
|
result += await this.Context.Updateable(addList)
|
||||||
|
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||||
|
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -515,6 +515,13 @@ namespace SqlSugar
|
|||||||
});
|
});
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
|
||||||
}
|
}
|
||||||
|
else if (item.NodeType == ExpressionType.Not
|
||||||
|
&& (item as UnaryExpression).Operand is MethodCallExpression
|
||||||
|
&& ((item as UnaryExpression).Operand as MethodCallExpression).Method.Name.IsIn("IsNullOrEmpty", "IsNullOrWhiteSpace"))
|
||||||
|
{
|
||||||
|
var asValue = packIfElse(GetNewExpressionValue(item)).ObjToString();
|
||||||
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, asValue));
|
||||||
|
}
|
||||||
else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
|
else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
|
||||||
{
|
{
|
||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
@ -526,7 +533,15 @@ namespace SqlSugar
|
|||||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public object packIfElse(object methodValue)
|
||||||
|
{
|
||||||
|
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
|
||||||
|
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
|
||||||
|
new KeyValuePair<string, string>("Return","1"),
|
||||||
|
new KeyValuePair<string, string>("End","0")
|
||||||
|
});
|
||||||
|
return methodValue;
|
||||||
|
}
|
||||||
private static bool IsNotCaseExpression(Expression item)
|
private static bool IsNotCaseExpression(Expression item)
|
||||||
{
|
{
|
||||||
if ((item as MethodCallExpression).Method.Name == "IIF")
|
if ((item as MethodCallExpression).Method.Name == "IIF")
|
||||||
|
@ -6,6 +6,8 @@ using Microsoft.Data.SqlClient;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class SqlServerProvider : AdoProvider
|
public class SqlServerProvider : AdoProvider
|
||||||
@ -131,10 +133,15 @@ namespace SqlSugar
|
|||||||
sqlParameter.Value = parameter.Value;
|
sqlParameter.Value = parameter.Value;
|
||||||
sqlParameter.DbType = parameter.DbType;
|
sqlParameter.DbType = parameter.DbType;
|
||||||
var isTime = parameter.DbType == System.Data.DbType.Time;
|
var isTime = parameter.DbType == System.Data.DbType.Time;
|
||||||
if (isTime)
|
if (isTime)
|
||||||
{
|
{
|
||||||
sqlParameter.SqlDbType = SqlDbType.Time;
|
sqlParameter.SqlDbType = SqlDbType.Time;
|
||||||
sqlParameter.Value=DateTime.Parse(parameter.Value?.ToString()).TimeOfDay;
|
sqlParameter.Value=DateTime.Parse(parameter.Value?.ToString()).TimeOfDay;
|
||||||
|
}
|
||||||
|
else if (parameter.Value!=null&¶meter.Value is XElement)
|
||||||
|
{
|
||||||
|
sqlParameter.SqlDbType = SqlDbType.Xml;
|
||||||
|
sqlParameter.Value= (parameter.Value as XElement).ToString();
|
||||||
}
|
}
|
||||||
if (sqlParameter.Value!=null&& sqlParameter.Value != DBNull.Value && sqlParameter.DbType == System.Data.DbType.DateTime)
|
if (sqlParameter.Value!=null&& sqlParameter.Value != DBNull.Value && sqlParameter.DbType == System.Data.DbType.DateTime)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user