diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs index 8b05bba33..f125f9a08 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs @@ -129,7 +129,17 @@ namespace SqlSugar if (model is ConditionalModel) { var item = model as ConditionalModel; - if (item.FieldName == $"[value=sql{UtilConstants.ReplaceKey}]") + if (item.CustomConditionalFunc != null) + { + var colIndex = mainIndex + beginIndex; + var colType = colIndex == 0 ? "" : "AND"; + var custom = item.CustomConditionalFunc.GetConditionalSql(item, colIndex); + parameters.AddRange(custom.Value); + builder.AppendFormat(" "+colType + " "+custom.Key); + mainIndex++; + continue; + } + else if (item.FieldName == $"[value=sql{UtilConstants.ReplaceKey}]") { builder.Append(item.FieldValue); continue; diff --git a/Src/Asp.Net/SqlSugar/Entities/ConditionalModel.cs b/Src/Asp.Net/SqlSugar/Entities/ConditionalModel.cs index c7dfbf306..1da3ef455 100644 --- a/Src/Asp.Net/SqlSugar/Entities/ConditionalModel.cs +++ b/Src/Asp.Net/SqlSugar/Entities/ConditionalModel.cs @@ -25,6 +25,14 @@ namespace SqlSugar public string FieldName { get; set; } public string FieldValue { get; set; } public string CSharpTypeName { get; set; } + + + public ICustomConditionalFunc CustomConditionalFunc { get; set; } + public string CustomP1 { get; set; } + public string CustomP2 { get; set; } + public string CustomP3 { get; set; } + public string CustomP4 { get; set; } + public ConditionalType ConditionalType { get; set; } [Newtonsoft.Json.JsonIgnoreAttribute] public Func FieldValueConvertFunc { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Interface/ICustomConditionalFunc.cs b/Src/Asp.Net/SqlSugar/Interface/ICustomConditionalFunc.cs new file mode 100644 index 000000000..b6fce1a38 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Interface/ICustomConditionalFunc.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SqlSugar +{ + public interface ICustomConditionalFunc + { + KeyValuePair GetConditionalSql(ConditionalModel json,int index); + } +} diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 0a9f8fe1e..c3abbd9e0 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -138,6 +138,7 @@ + diff --git a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs b/Src/Asp.Net/SqlSuga