Update Core

This commit is contained in:
sunkaixuan 2022-05-15 11:54:48 +08:00
parent 6352e499dd
commit 6d5518f656
6 changed files with 65 additions and 7 deletions

View File

@ -6,6 +6,7 @@ using System.Data;
using System.Reflection;
using System.Reflection.Emit;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace SqlSugar
{
@ -41,6 +42,7 @@ namespace SqlSugar
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
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 getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
@ -182,6 +184,21 @@ namespace SqlSugar
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
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)
{
@ -285,6 +302,10 @@ namespace SqlSugar
{
method = isNullableType ? getConvertStringGuid : getStringGuid;
}
else if (bindProperyTypeName == "xelement")
{
method = getXelement;
}
break;
case CSharpDataType.DateTime:
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);

View File

@ -3,12 +3,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml.Linq;
namespace SqlSugar
{
public static partial class IDataRecordExtensions
{
#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)
{
var result = Guid.Parse(dr.GetValue(i).ToString());

View File

@ -306,7 +306,11 @@ namespace SqlSugar
var queryable = this.Context.Queryable<T>();
queryable.QueryBuilder.LambdaExpressions.ParameterIndex= 1000;
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;
}
public SplitTableDeleteProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc)

View File

@ -24,7 +24,9 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName))
{
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;
}
@ -38,7 +40,9 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName))
{
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;
}

View File

@ -515,6 +515,13 @@ namespace SqlSugar
});
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)
{
this.Expression = item;
@ -526,7 +533,15 @@ namespace SqlSugar
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)
{
if ((item as MethodCallExpression).Method.Name == "IIF")

View File

@ -6,6 +6,8 @@ using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SqlSugar
{
public class SqlServerProvider : AdoProvider
@ -131,10 +133,15 @@ namespace SqlSugar
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = parameter.DbType;
var isTime = parameter.DbType == System.Data.DbType.Time;
if (isTime)
if (isTime)
{
sqlParameter.SqlDbType = SqlDbType.Time;
sqlParameter.Value=DateTime.Parse(parameter.Value?.ToString()).TimeOfDay;
sqlParameter.SqlDbType = SqlDbType.Time;
sqlParameter.Value=DateTime.Parse(parameter.Value?.ToString()).TimeOfDay;
}
else if (parameter.Value!=null&&parameter.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)
{