mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-30 22:10:22 +08:00
Support (int long dec dob Guid).ToString(format)
This commit is contained in:
parent
187704bf7e
commit
38947d05e3
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class QueryableFormat
|
||||
{
|
||||
public Type Type { get; set; }
|
||||
public string TypeString { get; set; }
|
||||
public string Format { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
public string MethodName { get; set; }
|
||||
}
|
||||
}
|
@ -1003,6 +1003,8 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region NoCopy
|
||||
|
||||
internal List<QueryableFormat> QueryableFormats { get; set; }
|
||||
internal bool IsClone { get; set; }
|
||||
public bool NoCheckInclude { get; set; }
|
||||
public virtual bool IsSelectNoAll { get; set; } = false;
|
||||
|
@ -18,6 +18,28 @@ namespace SqlSugar
|
||||
parameter.Context.Result.Append(this.Context.GetAsString2(asName, this.Context.DbMehtods.NewUid(null)));
|
||||
return;
|
||||
}
|
||||
else if (ExpressionTool.GetMethodName(item) == "ToString"
|
||||
&&(item as MethodCallExpression)?.Arguments?.Count()==1
|
||||
&& (item as MethodCallExpression)?.Object?.Type!=UtilConstants.DateType
|
||||
&& this.Context?.SugarContext?.QueryBuilder!=null)
|
||||
{
|
||||
var format=ExpressionTool.GetExpressionValue((item as MethodCallExpression)?.Arguments[0]);
|
||||
var childExpression = (item as MethodCallExpression)?.Object;
|
||||
var type=childExpression.Type;
|
||||
if (this.Context.SugarContext.QueryBuilder.QueryableFormats == null)
|
||||
{
|
||||
this.Context.SugarContext.QueryBuilder.QueryableFormats = new List<QueryableFormat>();
|
||||
}
|
||||
this.Context.SugarContext.QueryBuilder.QueryableFormats.Add(new QueryableFormat() {
|
||||
Format=format+"",
|
||||
PropertyName=asName,
|
||||
Type=type,
|
||||
TypeString=type.FullName,
|
||||
MethodName= "ToString"
|
||||
});
|
||||
parameter.Context.Result.Append(this.Context.GetAsString2(asName, GetNewExpressionValue(childExpression)));
|
||||
return;
|
||||
}
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
if (ExpressionTool.GetMethodName(item) == "MappingColumn")
|
||||
|
@ -482,6 +482,12 @@ namespace SqlSugar
|
||||
if (readerValues.Any(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
var addValue = readerValues.ContainsKey(name) ? readerValues[name] : readerValues.First(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Value;
|
||||
if (addValue!=null&&this.QueryBuilder?.QueryableFormats?.Any(it=>it.PropertyName==name)==true)
|
||||
{
|
||||
var valueFomatInfo = this.QueryBuilder?.QueryableFormats?.First(it => it.PropertyName == name);
|
||||
addValue =UtilMethods.GetFormatValue(addValue,valueFomatInfo);
|
||||
|
||||
}
|
||||
if (addValue == DBNull.Value || addValue == null)
|
||||
{
|
||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||
@ -524,6 +530,7 @@ namespace SqlSugar
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void SetAppendColumns(IDataReader dataReader)
|
||||
{
|
||||
|
@ -124,6 +124,7 @@
|
||||
<Compile Include="Abstract\InsertableProvider\InsertMethodInfo.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\Entities\AppendNavInfoList.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\Entities\QueryableAppendColumn.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\Entities\QueryableFormat.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\Entities\SqlInfo.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\Entities\SubQueryToListDefaultT.cs" />
|
||||
<Compile Include="Abstract\QueryableProvider\QueryableExecuteSqlAsync.cs" />
|
||||
|
@ -18,6 +18,51 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
/// <summary>
|
||||
/// Available only in Select,Handles logic that cannot be completed by an expression
|
||||
/// </summary>
|
||||
/// <param name="addValue"></param>
|
||||
/// <param name="valueFomatInfo"></param>
|
||||
/// <returns></returns>
|
||||
internal static object GetFormatValue(object addValue, QueryableFormat valueFomatInfo)
|
||||
{
|
||||
if (valueFomatInfo.MethodName == "ToString")
|
||||
{
|
||||
if (valueFomatInfo.Type == UtilConstants.GuidType)
|
||||
{
|
||||
addValue = Guid.Parse(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.ByteType)
|
||||
{
|
||||
addValue = Convert.ToByte(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.IntType)
|
||||
{
|
||||
addValue = Convert.ToInt32(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.LongType)
|
||||
{
|
||||
addValue = Convert.ToInt64(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.UIntType)
|
||||
{
|
||||
addValue = Convert.ToUInt32(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.ULongType)
|
||||
{
|
||||
addValue = Convert.ToUInt64(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.DecType)
|
||||
{
|
||||
addValue = Convert.ToDecimal(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
else if (valueFomatInfo.Type == UtilConstants.DobType)
|
||||
{
|
||||
addValue = Convert.ToDouble(addValue + "").ToString(valueFomatInfo.Format);
|
||||
}
|
||||
}
|
||||
return addValue;
|
||||
}
|
||||
public static int CountSubstringOccurrences(string mainString, string searchString)
|
||||
{
|
||||
string[] substrings = mainString.Split(new string[] { searchString }, StringSplitOptions.None);
|
||||
|
Loading…
Reference in New Issue
Block a user