mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-26 21:38:32 +08:00
Update core
This commit is contained in:
@@ -330,12 +330,20 @@ namespace SqlSugar
|
|||||||
WhereType = WhereType.Or;
|
WhereType = WhereType.Or;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cons.ConditionalList.Add(new KeyValuePair<WhereType, ConditionalModel>(WhereType, new ConditionalModel()
|
var data = new KeyValuePair<WhereType, ConditionalModel>(WhereType, new ConditionalModel()
|
||||||
{
|
{
|
||||||
ConditionalType = ConditionalType.Equal,
|
ConditionalType = ConditionalType.Equal,
|
||||||
FieldName = this.QueryBuilder.Builder.GetTranslationColumnName(column.DbColumnName),
|
FieldName = this.QueryBuilder.Builder.GetTranslationColumnName(column.DbColumnName),
|
||||||
FieldValue = value.ObjToString()
|
FieldValue = value.ObjToString()
|
||||||
}));
|
});
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||||
|
{
|
||||||
|
data.Value.FieldValueConvertFunc = it =>
|
||||||
|
{
|
||||||
|
return UtilMethods.ChangeType2(it, value.GetType());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
cons.ConditionalList.Add(data);
|
||||||
}
|
}
|
||||||
if (cons.HasValue())
|
if (cons.HasValue())
|
||||||
{
|
{
|
||||||
@@ -782,6 +790,10 @@ namespace SqlSugar
|
|||||||
result.QueryBuilder.WhereIndex = index;
|
result.QueryBuilder.WhereIndex = index;
|
||||||
result.QueryBuilder.LambdaExpressions.ParameterIndex = QueryBuilder.LambdaExpressions.ParameterIndex++;
|
result.QueryBuilder.LambdaExpressions.ParameterIndex = QueryBuilder.LambdaExpressions.ParameterIndex++;
|
||||||
result.QueryBuilder.LambdaExpressions.Index = QueryBuilder.LambdaExpressions.Index++;
|
result.QueryBuilder.LambdaExpressions.Index = QueryBuilder.LambdaExpressions.Index++;
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle)
|
||||||
|
{
|
||||||
|
result.Select("MergeTable.*");
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,6 +880,15 @@ namespace SqlSugar
|
|||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public async virtual Task<T[]> ToArrayAsync()
|
||||||
|
{
|
||||||
|
|
||||||
|
var result =await this.ToListAsync();
|
||||||
|
if (result.HasValue())
|
||||||
|
return result.ToArray();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public virtual string ToJson()
|
public virtual string ToJson()
|
||||||
{
|
{
|
||||||
if (IsCache)
|
if (IsCache)
|
||||||
@@ -1061,6 +1082,56 @@ namespace SqlSugar
|
|||||||
InitMapping();
|
InitMapping();
|
||||||
return _ToList<T>();
|
return _ToList<T>();
|
||||||
}
|
}
|
||||||
|
public List<T> ToOffsetPage(int pageIndex, int pageSize)
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||||
|
{
|
||||||
|
return this.ToPageList(pageIndex, pageSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ToOffsetPage(pageIndex, pageSize);
|
||||||
|
return this.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<T> ToOffsetPage(int pageIndex, int pageSize, ref int totalNumber)
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||||
|
{
|
||||||
|
return this.ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalNumber = this.Clone().Count();
|
||||||
|
_ToOffsetPage(pageIndex, pageSize);
|
||||||
|
return this.Clone().ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Task<List<T>> ToOffsetPageAsync(int pageIndex, int pageSize)
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||||
|
{
|
||||||
|
return this.ToPageListAsync(pageIndex, pageSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ToOffsetPage(pageIndex, pageSize);
|
||||||
|
return this.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<List<T>> ToOffsetPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||||
|
{
|
||||||
|
return await this.ToPageListAsync(pageIndex, pageSize, totalNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalNumber.Value =await this.Clone().CountAsync();
|
||||||
|
_ToOffsetPage(pageIndex, pageSize);
|
||||||
|
return await this.Clone().ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
public virtual List<T> ToPageList(int pageIndex, int pageSize)
|
public virtual List<T> ToPageList(int pageIndex, int pageSize)
|
||||||
{
|
{
|
||||||
pageIndex = _PageList(pageIndex, pageSize);
|
pageIndex = _PageList(pageIndex, pageSize);
|
||||||
@@ -1487,6 +1558,11 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void _ToOffsetPage(int pageIndex, int pageSize)
|
||||||
|
{
|
||||||
|
QueryBuilder.Offset = $" OFFSET {(pageIndex - 1) * pageSize} ROWS FETCH NEXT {pageSize} ROWS ONLY";
|
||||||
|
}
|
||||||
|
|
||||||
private int _PageList(int pageIndex, int pageSize)
|
private int _PageList(int pageIndex, int pageSize)
|
||||||
{
|
{
|
||||||
if (pageIndex == 0)
|
if (pageIndex == 0)
|
||||||
@@ -2267,6 +2343,7 @@ namespace SqlSugar
|
|||||||
asyncQueryableBuilder.IgnoreColumns = this.QueryBuilder.IgnoreColumns;
|
asyncQueryableBuilder.IgnoreColumns = this.QueryBuilder.IgnoreColumns;
|
||||||
asyncQueryableBuilder.AsTables = this.QueryBuilder.AsTables;
|
asyncQueryableBuilder.AsTables = this.QueryBuilder.AsTables;
|
||||||
asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop;
|
asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop;
|
||||||
|
asyncQueryableBuilder.Offset = this.QueryBuilder.Offset;
|
||||||
}
|
}
|
||||||
protected int SetCacheTime(int cacheDurationInSeconds)
|
protected int SetCacheTime(int cacheDurationInSeconds)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class ReportableProvider<T> : IReportable<T>
|
||||||
|
{
|
||||||
|
public SqlSugarProvider Context { get; set; }
|
||||||
|
private List<T> datas = new List<T>();
|
||||||
|
private List<DateTime> dates = new List<DateTime>();
|
||||||
|
private bool isDates = false;
|
||||||
|
internal QueryBuilder queryBuilder;
|
||||||
|
internal InsertBuilder formatBuilder { get; set; }
|
||||||
|
|
||||||
|
public ReportableProvider(T data)
|
||||||
|
{
|
||||||
|
datas.Add(data);
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportableProvider(List<T> list)
|
||||||
|
{
|
||||||
|
datas = list;
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
//public IReportable<T> MakeUp(Func<T, object> auto)
|
||||||
|
//{
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
//}
|
||||||
|
|
||||||
|
public ISugarQueryable<T> ToQueryable()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (datas.Any())
|
||||||
|
{
|
||||||
|
if (isDates)
|
||||||
|
{
|
||||||
|
var da = this.dates;
|
||||||
|
Each(sb, da);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var da = this.datas;
|
||||||
|
Each(sb, da);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (typeof(T).IsClass())
|
||||||
|
{
|
||||||
|
|
||||||
|
var result = (T)Activator.CreateInstance(typeof(T), true);
|
||||||
|
datas.Add(result);
|
||||||
|
ClassMethod(result, sb, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append("SELECT NULL as ColumnName ");
|
||||||
|
sb.Append(GetNextSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.Context.SqlQueryable<object>(sb.ToString()).Select<T>();
|
||||||
|
}
|
||||||
|
public ISugarQueryable<SingleColumnEntity<Y>> ToQueryable<Y>()
|
||||||
|
{
|
||||||
|
return ToQueryable().Select<SingleColumnEntity<Y>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Each<Y>(StringBuilder sb, List<Y> list)
|
||||||
|
{
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
var isLast = list.IndexOf(item) == list.Count - 1;
|
||||||
|
var isClass = typeof(T).IsClass();
|
||||||
|
if (isClass)
|
||||||
|
{
|
||||||
|
ClassMethod(item, sb, isLast);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NoClassMethod(item, sb, isLast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClassMethod<Y>(Y data, StringBuilder sb,bool isLast)
|
||||||
|
{
|
||||||
|
var columns = new StringBuilder();
|
||||||
|
var entity=this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||||
|
columns.Append(string.Join(",",entity.Columns.Where(it=>it.IsIgnore==false).Select(it=>GetSelect(it,data))));
|
||||||
|
columns.Append(",null as NoCacheColumn");
|
||||||
|
sb.AppendLine(" SELECT " + columns.ToString());
|
||||||
|
sb.Append(GetNextSql);
|
||||||
|
if (!isLast)
|
||||||
|
{
|
||||||
|
sb.AppendLine(" UNION ALL ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object GetSelect<Y>(EntityColumnInfo it,Y data)
|
||||||
|
{
|
||||||
|
|
||||||
|
return string.Format(" {0} AS {1} ", FormatValue(it.PropertyInfo.GetValue(data,null)),it.PropertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NoClassMethod<Y>(Y data, StringBuilder sb,bool isLast)
|
||||||
|
{
|
||||||
|
sb.AppendLine(" SELECT "+ FormatValue(data));
|
||||||
|
sb.Append(" AS ColumnName ");
|
||||||
|
sb.Append(GetNextSql);
|
||||||
|
if (!isLast)
|
||||||
|
{
|
||||||
|
sb.AppendLine(" UNION ALL ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string GetNextSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle)
|
||||||
|
{
|
||||||
|
return " from dual ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void Init()
|
||||||
|
{
|
||||||
|
if (datas.Count == 1)
|
||||||
|
{
|
||||||
|
isDates = true;
|
||||||
|
var data=datas.First();
|
||||||
|
if (data is ReportableDateType)
|
||||||
|
{
|
||||||
|
var type = UtilMethods.ChangeType2(data, typeof(ReportableDateType));
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ReportableDateType.MonthsInLast1years:
|
||||||
|
dates.AddRange(GetMonths(1));
|
||||||
|
break;
|
||||||
|
case ReportableDateType.MonthsInLast3years:
|
||||||
|
dates.AddRange(GetMonths(3));
|
||||||
|
break;
|
||||||
|
case ReportableDateType.MonthsInLast10years:
|
||||||
|
dates.AddRange(GetMonths(10));
|
||||||
|
break;
|
||||||
|
case ReportableDateType.years1:
|
||||||
|
dates.AddRange(GetYears(1));
|
||||||
|
break;
|
||||||
|
case ReportableDateType.years3:
|
||||||
|
dates.AddRange(GetYears(3));
|
||||||
|
break;
|
||||||
|
case ReportableDateType.years10:
|
||||||
|
dates.AddRange(GetYears(10));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DateTime> GetYears(int v)
|
||||||
|
{
|
||||||
|
List<DateTime> result = new List<DateTime>();
|
||||||
|
for (int i = 0; i < v; i++)
|
||||||
|
{
|
||||||
|
var year= (DateTime.Now.AddYears(i * -1).Year+"-01"+"-01").ObjToDate();
|
||||||
|
result.Add(year);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private List<DateTime> GetMonths(int v)
|
||||||
|
{
|
||||||
|
List<DateTime> result = new List<DateTime>();
|
||||||
|
var years = GetYears(v);
|
||||||
|
foreach (var item in years)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
result.Add(item.AddMonths(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private object FormatValue(object value)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
return "null";
|
||||||
|
var type =UtilMethods.GetUnderType(value.GetType());
|
||||||
|
if (type.IsIn(typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(short), typeof(ushort)))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if (type.IsIn(typeof(decimal), typeof(double)))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if (type.IsIn(typeof(DateTime)))
|
||||||
|
{
|
||||||
|
Expression<Func<SingleColumnEntity<object>, object>> exp= it => Convert.ToDateTime(it.ColumnName);
|
||||||
|
var result= queryBuilder.GetExpressionValue(exp,ResolveExpressType.WhereSingle).GetResultString();
|
||||||
|
result = Regex.Replace(result, @"\[ColumnName\]", formatBuilder.FormatValue(value)+"",RegexOptions.IgnoreCase);
|
||||||
|
result = Regex.Replace(result, @"\`ColumnName\`", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
|
||||||
|
result = Regex.Replace(result, @"""ColumnName""", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return formatBuilder.FormatValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -477,6 +477,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Get SQL Partial
|
#region Get SQL Partial
|
||||||
|
public string Offset { get; set; }
|
||||||
public virtual string GetSelectValue
|
public virtual string GetSelectValue
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -640,6 +641,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private string GetTableName(string entityName)
|
private string GetTableName(string entityName)
|
||||||
|
|||||||
@@ -754,6 +754,38 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Reportable
|
||||||
|
public IReportable<T> Reportable<T>(T data)
|
||||||
|
{
|
||||||
|
var result = new ReportableProvider<T>(data);
|
||||||
|
result.formatBuilder = InstanceFactory.GetInsertBuilder(this.Context.CurrentConnectionConfig);
|
||||||
|
result.Context = this;
|
||||||
|
result.formatBuilder.Context = this;
|
||||||
|
result.queryBuilder = this.Queryable<object>().QueryBuilder;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public IReportable<T> Reportable<T>(List<T> list)
|
||||||
|
{
|
||||||
|
var result = new ReportableProvider<T>(list);
|
||||||
|
result.formatBuilder = InstanceFactory.GetInsertBuilder(this.Context.CurrentConnectionConfig);
|
||||||
|
result.Context = this;
|
||||||
|
result.formatBuilder.Context = this;
|
||||||
|
result.queryBuilder = this.Queryable<object>().QueryBuilder;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public IReportable<T> Reportable<T>(T [] list)
|
||||||
|
{
|
||||||
|
if (list == null)
|
||||||
|
list = new T[] { };
|
||||||
|
var result = new ReportableProvider<T>(list.ToList());
|
||||||
|
result.formatBuilder = InstanceFactory.GetInsertBuilder(this.Context.CurrentConnectionConfig);
|
||||||
|
result.Context = this;
|
||||||
|
result.formatBuilder.Context = this;
|
||||||
|
result.queryBuilder = this.Queryable<object>().QueryBuilder;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region DbFirst
|
#region DbFirst
|
||||||
public virtual IDbFirst DbFirst
|
public virtual IDbFirst DbFirst
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SingleColumnEntity<T>
|
||||||
|
{
|
||||||
|
public T ColumnName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public enum ReportableDateType
|
||||||
|
{
|
||||||
|
MonthsInLast1years=0,
|
||||||
|
MonthsInLast3years=1,
|
||||||
|
MonthsInLast10years=2,
|
||||||
|
years1=3,
|
||||||
|
years3=4,
|
||||||
|
years10=5
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -131,7 +131,7 @@ namespace SqlSugar
|
|||||||
foreach (var item in entity.Parameter)
|
foreach (var item in entity.Parameter)
|
||||||
{
|
{
|
||||||
var oldName = item.ParameterName;
|
var oldName = item.ParameterName;
|
||||||
item.ParameterName = oldName + "_con_" + this.Context.ParameterIndex;
|
item.ParameterName = Regex.Split(oldName,"_con_").First() + "_con_" + this.Context.ParameterIndex;
|
||||||
entity.Where = entity.Where.Replace(oldName, item.ParameterName);
|
entity.Where = entity.Where.Replace(oldName, item.ParameterName);
|
||||||
}
|
}
|
||||||
this.Context.ParameterIndex++;
|
this.Context.ParameterIndex++;
|
||||||
|
|||||||
@@ -41,10 +41,18 @@ namespace SqlSugar
|
|||||||
case ResolveExpressType.ArrayMultiple:
|
case ResolveExpressType.ArrayMultiple:
|
||||||
case ResolveExpressType.ArraySingle:
|
case ResolveExpressType.ArraySingle:
|
||||||
foreach (var item in expression.Arguments)
|
foreach (var item in expression.Arguments)
|
||||||
|
{
|
||||||
|
if (IsDateValue(item))
|
||||||
|
{
|
||||||
|
var value = GetNewExpressionValue(item);
|
||||||
|
base.Context.Result.Append(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
base.Expression = item;
|
base.Expression = item;
|
||||||
base.Start();
|
base.Start();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ResolveExpressType.Join:
|
case ResolveExpressType.Join:
|
||||||
base.Context.ResolveType = ResolveExpressType.WhereMultiple;
|
base.Context.ResolveType = ResolveExpressType.WhereMultiple;
|
||||||
@@ -75,6 +83,25 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsDateValue(Expression item)
|
||||||
|
{
|
||||||
|
var isMember = item is MemberExpression;
|
||||||
|
if (isMember)
|
||||||
|
{
|
||||||
|
var m = (item as MemberExpression);
|
||||||
|
var isInt= m.Type == UtilConstants.IntType;
|
||||||
|
if (m.Expression != null && isInt&& m.Expression is MemberExpression)
|
||||||
|
{
|
||||||
|
var mm = (m.Expression as MemberExpression);
|
||||||
|
if (m.Member.Name.IsIn("Year", "Day", "Month")&&mm.Type==UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void NewValueType(ExpressionParameter parameter, NewExpression expression)
|
private void NewValueType(ExpressionParameter parameter, NewExpression expression)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -290,6 +290,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result.Add(name, (byte[])readerValues[item.Name.ToLower()]);
|
result.Add(name, (byte[])readerValues[item.Name.ToLower()]);
|
||||||
}
|
}
|
||||||
|
else if (item.PropertyType == typeof(object))
|
||||||
|
{
|
||||||
|
result.Add(name, readerValues[item.Name.ToLower()]);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval));
|
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval));
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ namespace SqlSugar
|
|||||||
Task<List<Dictionary<string, object>>> ToDictionaryListAsync();
|
Task<List<Dictionary<string, object>>> ToDictionaryListAsync();
|
||||||
|
|
||||||
T[] ToArray();
|
T[] ToArray();
|
||||||
|
Task<T[]> ToArrayAsync();
|
||||||
Task<List<T>> ToListAsync();
|
Task<List<T>> ToListAsync();
|
||||||
|
|
||||||
string ToJson();
|
string ToJson();
|
||||||
@@ -154,6 +155,10 @@ namespace SqlSugar
|
|||||||
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
|
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
|
||||||
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||||
|
|
||||||
|
List<T> ToOffsetPage(int pageIndex,int pageSize);
|
||||||
|
List<T> ToOffsetPage(int pageIndex, int pageSize,ref int totalNumber);
|
||||||
|
Task<List<T>> ToOffsetPageAsync(int pageIndex, int pageSize);
|
||||||
|
Task<List<T>> ToOffsetPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||||
List<T> ToPageList(int pageIndex, int pageSize);
|
List<T> ToPageList(int pageIndex, int pageSize);
|
||||||
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize);
|
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize);
|
||||||
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber);
|
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public interface IReportable<T>
|
||||||
|
{
|
||||||
|
//IReportable<T> MakeUp(Func<T,object> auto);
|
||||||
|
ISugarQueryable<T> ToQueryable();
|
||||||
|
ISugarQueryable<SingleColumnEntity<Y>> ToQueryable<Y>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,14 @@ namespace SqlSugar
|
|||||||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
||||||
}
|
}
|
||||||
this.OrderByValue = oldOrderBy;
|
this.OrderByValue = oldOrderBy;
|
||||||
|
if (!string.IsNullOrEmpty(this.Offset))
|
||||||
|
{
|
||||||
|
if (this.OrderByValue.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
result += " ORDER BY GETDATE() ";
|
||||||
|
}
|
||||||
|
result += this.Offset;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,6 +358,21 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Reportable
|
||||||
|
public IReportable<T> Reportable<T>(T data)
|
||||||
|
{
|
||||||
|
return this.Context.Reportable(data);
|
||||||
|
}
|
||||||
|
public IReportable<T> Reportable<T>(List<T> list)
|
||||||
|
{
|
||||||
|
return this.Context.Reportable(list);
|
||||||
|
}
|
||||||
|
public IReportable<T> Reportable<T>(T [] array)
|
||||||
|
{
|
||||||
|
return this.Context.Reportable(array);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Queue
|
#region Queue
|
||||||
public QueueList Queues { get { return this.Context.Queues; } set { this.Context.Queues = value; } }
|
public QueueList Queues { get { return this.Context.Queues; } set { this.Context.Queues = value; } }
|
||||||
public void AddQueue(string sql, object parsmeters = null)
|
public void AddQueue(string sql, object parsmeters = null)
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ namespace SqlSugar
|
|||||||
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName)," "+ newName + "+", RegexOptions.IgnoreCase);
|
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName)," "+ newName + "+", RegexOptions.IgnoreCase);
|
||||||
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
|
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
|
||||||
itemSql = Regex.Replace(itemSql, string.Format(@"\={0}\+", "\\" + itemParameter.ParameterName), "=" + newName + "+", RegexOptions.IgnoreCase);
|
itemSql = Regex.Replace(itemSql, string.Format(@"\={0}\+", "\\" + itemParameter.ParameterName), "=" + newName + "+", RegexOptions.IgnoreCase);
|
||||||
|
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\|\|", "\\" + itemParameter.ParameterName), newName + "+", RegexOptions.IgnoreCase);
|
||||||
return itemSql;
|
return itemSql;
|
||||||
}
|
}
|
||||||
internal static Type GetRootBaseType(Type entityType)
|
internal static Type GetRootBaseType(Type entityType)
|
||||||
@@ -182,6 +183,29 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return returnObj;
|
return returnObj;
|
||||||
}
|
}
|
||||||
|
public static object ChangeType2(object value, Type type)
|
||||||
|
{
|
||||||
|
if (value == null && type.IsGenericType) return Activator.CreateInstance(type);
|
||||||
|
if (value == null) return null;
|
||||||
|
if (type == value.GetType()) return value;
|
||||||
|
if (type.IsEnum)
|
||||||
|
{
|
||||||
|
if (value is string)
|
||||||
|
return Enum.Parse(type, value as string);
|
||||||
|
else
|
||||||
|
return Enum.ToObject(type, value);
|
||||||
|
}
|
||||||
|
if (!type.IsInterface && type.IsGenericType)
|
||||||
|
{
|
||||||
|
Type innerType = type.GetGenericArguments()[0];
|
||||||
|
object innerValue = ChangeType(value, innerType);
|
||||||
|
return Activator.CreateInstance(type, new object[] { innerValue });
|
||||||
|
}
|
||||||
|
if (value is string && type == typeof(Guid)) return new Guid(value as string);
|
||||||
|
if (value is string && type == typeof(Version)) return new Version(value as string);
|
||||||
|
if (!(value is IConvertible)) return value;
|
||||||
|
return Convert.ChangeType(value, type);
|
||||||
|
}
|
||||||
|
|
||||||
internal static T ChangeType<T>(T obj, Type type)
|
internal static T ChangeType<T>(T obj, Type type)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user