mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update core
This commit is contained in:
parent
6bb06e4c04
commit
456b75355a
@ -77,10 +77,15 @@ namespace SqlSugar
|
||||
{
|
||||
CheckConnection();
|
||||
}
|
||||
public virtual void OpenAlways()
|
||||
public SugarConnection OpenAlways()
|
||||
{
|
||||
SugarConnection result = new SugarConnection();
|
||||
result.IsAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection;
|
||||
result.conn = this.Connection;
|
||||
result.Context = this.Context;
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
this.Open();
|
||||
return result;
|
||||
}
|
||||
public virtual void Close()
|
||||
{
|
||||
|
@ -325,6 +325,12 @@ namespace SqlSugar
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false)
|
||||
{
|
||||
string sql = string.Format("CREATE {3} INDEX {2} ON {0}({1})", tableName, string.Join(",", columnNames), IndexName, isUnique ? "UNIQUE" : "");
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool IsAnyIndex(string indexName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyIndexSql, indexName);
|
||||
|
@ -166,7 +166,7 @@ namespace SqlSugar
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return xeNode.Element("summary").Value.Trim();
|
||||
return xeNode.Element("summary").Value.ToSqlFilter().Trim();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the code annotation for the database table
|
||||
|
@ -99,6 +99,10 @@ namespace SqlSugar
|
||||
var removeCacheFunc = inserable.RemoveCacheFunc;
|
||||
var objects = inserable.InsertObjs;
|
||||
var identityList = inserable.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.PropertyName).ToArray();
|
||||
if (inserable.IsOffIdentity)
|
||||
{
|
||||
identityList = new string[] { };
|
||||
}
|
||||
this.Context.Utilities.PageEach(objects, 100, pagelist =>
|
||||
{
|
||||
|
||||
@ -120,6 +124,10 @@ namespace SqlSugar
|
||||
var removeCacheFunc = inserable.RemoveCacheFunc;
|
||||
var objects = inserable.InsertObjs;
|
||||
var identityList = inserable.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.PropertyName).ToArray();
|
||||
if (inserable.IsOffIdentity)
|
||||
{
|
||||
identityList = new string[] { };
|
||||
}
|
||||
await this.Context.Utilities.PageEachAsync(objects, 100,async pagelist =>
|
||||
{
|
||||
|
||||
|
@ -485,6 +485,18 @@ namespace SqlSugar
|
||||
FieldName = column.DbColumnName,
|
||||
FieldValue = value.ObjToString()
|
||||
});
|
||||
if (value != null && value.GetType().IsEnum())
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString == true)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Value.FieldValue = Convert.ToInt64(value).ObjToString();
|
||||
}
|
||||
|
||||
}
|
||||
cons.ConditionalList.Add(data);
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||
{
|
||||
@ -1136,16 +1148,16 @@ namespace SqlSugar
|
||||
var parentIdName = UtilConvert.ToMemberExpression((parentIdExpression as LambdaExpression).Body).Member.Name;
|
||||
var ParentInfo = entity.Columns.First(it => it.PropertyName == parentIdName);
|
||||
var parentPropertyName = ParentInfo.DbColumnName;
|
||||
var current =await this.Context.Queryable<T>().InSingleAsync(primaryKeyValue);
|
||||
var current =await this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingleAsync(primaryKeyValue);
|
||||
if (current != null)
|
||||
{
|
||||
result.Add(current);
|
||||
object parentId = ParentInfo.PropertyInfo.GetValue(current, null);
|
||||
int i = 0;
|
||||
while (parentId != null &&await this.Context.Queryable<T>().In(parentId).AnyAsync())
|
||||
while (parentId != null &&await this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).In(parentId).AnyAsync())
|
||||
{
|
||||
Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限(100),检查最顶层的ParentId是否是null或者0"));
|
||||
var parent =await this.Context.Queryable<T>().InSingleAsync(parentId);
|
||||
var parent =await this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingleAsync(parentId);
|
||||
result.Add(parent);
|
||||
parentId = ParentInfo.PropertyInfo.GetValue(parent, null);
|
||||
++i;
|
||||
@ -2161,6 +2173,10 @@ namespace SqlSugar
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList();
|
||||
if (inValues!=null&& inValues.Any()&&UtilMethods.GetUnderType(entitys.First().GetType().GetProperty(filedName).PropertyType) == UtilConstants.GuidType)
|
||||
{
|
||||
inValues = inValues.Select(x => x == "" ? "null" : x).Distinct().ToList();
|
||||
}
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
|
@ -243,7 +243,7 @@ namespace SqlSugar
|
||||
}
|
||||
resolveExpress.RootExpression = expression;
|
||||
resolveExpress.JoinQueryInfos = Builder.QueryBuilder.JoinQueryInfos;
|
||||
resolveExpress.IsSingle = IsSingle();
|
||||
resolveExpress.IsSingle = IsSingle()&& resolveType!= ResolveExpressType.WhereMultiple;
|
||||
resolveExpress.MappingColumns = Context.MappingColumns;
|
||||
resolveExpress.MappingTables = Context.MappingTables;
|
||||
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||
@ -641,12 +641,12 @@ namespace SqlSugar
|
||||
result += UtilConstants.Space;
|
||||
if (IsSingle() && result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable") && TableShortName != null)
|
||||
{
|
||||
result = result.Replace(") MergeTable ", ") " + TableShortName);
|
||||
result = result.Replace(") MergeTable ", ") " + TableShortName+UtilConstants.Space);
|
||||
TableShortName = null;
|
||||
}
|
||||
if (IsSingle() && result.Contains("unionTable") && result.Trim().EndsWith(" unionTable")&& TableShortName!=null)
|
||||
{
|
||||
result = result.Replace(" ) unionTable ", ") "+TableShortName);
|
||||
result = result.Replace(" ) unionTable ", ") "+TableShortName + UtilConstants.Space);
|
||||
TableShortName = null;
|
||||
}
|
||||
if (this.TableShortName.HasValue())
|
||||
|
@ -189,12 +189,36 @@ namespace SqlSugar
|
||||
case ConditionalType.In:
|
||||
if (item.FieldValue == null) item.FieldValue = string.Empty;
|
||||
var inValue1 = ("(" + item.FieldValue.Split(',').ToJoinSqlInVals() + ")");
|
||||
if (item.CSharpTypeName.HasValue()&&UtilMethods.IsNumber(item.CSharpTypeName))
|
||||
{
|
||||
inValue1= inValue1.Replace("'","");
|
||||
}
|
||||
else if(inValue1.Contains("'null'"))
|
||||
{
|
||||
inValue1 = inValue1.Replace("'null'", "null");
|
||||
}
|
||||
else if (inValue1.Contains("[null]"))
|
||||
{
|
||||
inValue1 = inValue1.Replace("[null]", "null");
|
||||
}
|
||||
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "IN", inValue1);
|
||||
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
||||
break;
|
||||
case ConditionalType.NotIn:
|
||||
if (item.FieldValue == null) item.FieldValue = string.Empty;
|
||||
var inValue2 = ("(" + item.FieldValue.Split(',').ToJoinSqlInVals() + ")");
|
||||
if (item.CSharpTypeName.HasValue() && UtilMethods.IsNumber(item.CSharpTypeName))
|
||||
{
|
||||
inValue2 = inValue2.Replace("'", "");
|
||||
}
|
||||
else if (inValue2.Contains("'null'"))
|
||||
{
|
||||
inValue2 = inValue2.Replace("'null'", "null");
|
||||
}
|
||||
else if (inValue2.Contains("[null]"))
|
||||
{
|
||||
inValue2 = inValue2.Replace("[null]", "null");
|
||||
}
|
||||
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "NOT IN", inValue2);
|
||||
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
||||
break;
|
||||
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SugarConnection:IDisposable
|
||||
{
|
||||
public IDbConnection conn { get; set; }
|
||||
public bool IsAutoClose { get; set; }
|
||||
public ISqlSugarClient Context { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
conn.Close();
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = IsAutoClose;
|
||||
}
|
||||
}
|
||||
}
|
@ -532,6 +532,26 @@ namespace SqlSugar
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((item as MethodCallExpression).Method.Name== "AggregateMax")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((item as MethodCallExpression).Method.Name == "AggregateMin")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((item as MethodCallExpression).Method.Name == "AggregateSum")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((item as MethodCallExpression).Method.Name == "ToBool")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((item as MethodCallExpression).Method.Name == "ToBoolean")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
|
@ -1006,6 +1006,10 @@ namespace SqlSugar
|
||||
{
|
||||
return string.Format("CONVERT(varchar(100),convert(datetime,{0}), {1})", value, formatString);
|
||||
}
|
||||
else if (IsSqlServer())
|
||||
{
|
||||
return string.Format("FORMAT({0},'{1}','en-US')", value, formatString);
|
||||
}
|
||||
var parameter = new MethodCallExpressionArgs() { IsMember = true, MemberValue = DateType.Year };
|
||||
var parameter2 = new MethodCallExpressionArgs() { IsMember = true, MemberName = value };
|
||||
var parameters = new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() { parameter2, parameter } };
|
||||
|
@ -163,7 +163,7 @@ namespace SqlSugar
|
||||
void Dispose();
|
||||
void Close();
|
||||
void Open();
|
||||
void OpenAlways();
|
||||
SugarConnection OpenAlways();
|
||||
void CheckConnection();
|
||||
|
||||
void BeginTran();
|
||||
|
@ -29,6 +29,7 @@ namespace SqlSugar
|
||||
#region DDL
|
||||
bool AddDefaultValue(string tableName,string columnName,string defaultValue);
|
||||
bool CreateIndex(string tableName, string [] columnNames, bool isUnique=false);
|
||||
bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false);
|
||||
bool DropTable(string tableName);
|
||||
bool TruncateTable(string tableName);
|
||||
bool TruncateTable<T>();
|
||||
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT NAME FROM MASTER.DBO.SYSDATABASES ORDER BY NAME";
|
||||
return "SELECT NAME FROM master.dbo.sysdatabases ORDER BY NAME";
|
||||
}
|
||||
}
|
||||
protected override string GetColumnInfosByTableNameSql
|
||||
|
@ -20,6 +20,19 @@ namespace SqlSugar
|
||||
}
|
||||
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
|
||||
{
|
||||
public override string DateValue(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter2 = model.Args[1];
|
||||
if (parameter.MemberName != null && parameter.MemberName is DateTime)
|
||||
{
|
||||
return string.Format(" datepart({0},'{1}') ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Format(" datepart({0},{1}) ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
}
|
||||
public override string HasValue(MethodCallExpressionModel model)
|
||||
{
|
||||
if (model.Args[0].Type == UtilConstants.GuidType)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Version>5.0.5.9</Version>
|
||||
<Version>5.0.6</Version>
|
||||
<Copyright>sun_kai_xuan</Copyright>
|
||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
|
@ -2,16 +2,16 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>SqlSugarCore</id>
|
||||
<version>5.0.5.9</version>
|
||||
<version>5.0.6</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<owners>果糖大数据科技</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
<projectUrl>https://github.com/sunkaixuan/SqlSugar</projectUrl>
|
||||
<iconUrl>https://secure.gravatar.com/avatar/a82c03402497b2e58fd65038a3699b30</iconUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>5.0.3.5-Max 最低要求.Net Core 3.0+ ,5.0.0-5.0.3.4 最低要求 .Net Core 2.0+ SqlSugar ORM ,High-performance, lightweight </description>
|
||||
<copyright>Copyright 2016</copyright>
|
||||
<tags>Asp.net core orm</tags>
|
||||
<tags>SqlSugar Sql Sugar core Asp.net core orm</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard2.1">
|
||||
<dependency id="System.Data.Common" version="4.3.0" />
|
||||
|
@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>SqlSugarCoreNoDrive</id>
|
||||
<version>5.0.5.9</version>
|
||||
<version>5.0.6</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
@ -11,7 +11,7 @@
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description> .Net Core/.net5 SqlSugar ORM ,High-performance, lightweight https://github.com/sunkaixuan/SqlSugar</description>
|
||||
<copyright>Copyright 2016</copyright>
|
||||
<tags>Asp.net core orm</tags>
|
||||
<tags>SqlSugar Sql Sugar Core Asp.net core orm</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard2.1">
|
||||
<dependency id="System.Data.Common" version="4.3.0" />
|
||||
|
Loading…
Reference in New Issue
Block a user