mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-09 10:55:02 +08:00
Update Core
This commit is contained in:
@@ -366,7 +366,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(ec.DataType))
|
if (!string.IsNullOrEmpty(ec.DataType))
|
||||||
{
|
{
|
||||||
return ec.DataType != dc.DataType;
|
if (ec.IsIdentity && dc.IsIdentity)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ec.DataType != dc.DataType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var propertyType = UtilMethods.GetUnderType(ec.PropertyInfo);
|
var propertyType = UtilMethods.GetUnderType(ec.PropertyInfo);
|
||||||
var properyTypeName = string.Empty;
|
var properyTypeName = string.Empty;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -16,6 +17,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void InitTables(Type type)
|
public void InitTables(Type type)
|
||||||
|
{
|
||||||
|
var isSplitEntity = type.GetCustomAttributes<SplitTableAttribute>() != null;
|
||||||
|
if (isSplitEntity)
|
||||||
|
{
|
||||||
|
_InitTables(type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Context.CodeFirst.InitTables(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void _InitTables(Type type)
|
||||||
{
|
{
|
||||||
//var oldMapping = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
//var oldMapping = this.Context.Utilities.TranslateCopy(this.Context.MappingTables);
|
||||||
SplitTableContext helper = new SplitTableContext(Context)
|
SplitTableContext helper = new SplitTableContext(Context)
|
||||||
|
|||||||
@@ -206,7 +206,8 @@ namespace SqlSugar
|
|||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
if (isAddNotNUll)
|
if (isAddNotNUll)
|
||||||
{
|
{
|
||||||
var dtColums = this.Context.Queryable<object>().AS(columnInfo.TableName).Where("1=2").ToDataTable().Columns.Cast<System.Data.DataColumn>();
|
var dtColums = this.Context.Queryable<object>().AS(columnInfo.TableName).Where("1=2")
|
||||||
|
.Select(this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName)).ToDataTable().Columns.Cast<System.Data.DataColumn>();
|
||||||
var dtColumInfo = dtColums.First(it => it.ColumnName.EqualCase(columnInfo.DbColumnName));
|
var dtColumInfo = dtColums.First(it => it.ColumnName.EqualCase(columnInfo.DbColumnName));
|
||||||
var type = UtilMethods.GetUnderType(dtColumInfo.DataType);
|
var type = UtilMethods.GetUnderType(dtColumInfo.DataType);
|
||||||
var value= type==UtilConstants.StringType?(object)"": Activator.CreateInstance(type);
|
var value= type==UtilConstants.StringType?(object)"": Activator.CreateInstance(type);
|
||||||
|
|||||||
@@ -203,6 +203,14 @@ namespace SqlSugar
|
|||||||
object setValue = 0;
|
object setValue = 0;
|
||||||
if (idValue > int.MaxValue)
|
if (idValue > int.MaxValue)
|
||||||
setValue = idValue;
|
setValue = idValue;
|
||||||
|
else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(uint)))
|
||||||
|
{
|
||||||
|
setValue = Convert.ToUInt32(idValue);
|
||||||
|
}
|
||||||
|
else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ulong)))
|
||||||
|
{
|
||||||
|
setValue = Convert.ToUInt64(idValue);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
setValue = Convert.ToInt32(idValue);
|
setValue = Convert.ToInt32(idValue);
|
||||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||||
|
|||||||
@@ -2943,6 +2943,7 @@ namespace SqlSugar
|
|||||||
_Size=it._Size
|
_Size=it._Size
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery;
|
||||||
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;
|
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;
|
||||||
asyncQueryableBuilder.Take = this.QueryBuilder.Take;
|
asyncQueryableBuilder.Take = this.QueryBuilder.Take;
|
||||||
asyncQueryableBuilder.Skip = this.QueryBuilder.Skip;
|
asyncQueryableBuilder.Skip = this.QueryBuilder.Skip;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Splicing basic
|
#region Splicing basic
|
||||||
|
public bool IsQueryInQuery { get; set; }
|
||||||
public List<object> Includes { get; set; }
|
public List<object> Includes { get; set; }
|
||||||
public List<string> IgnoreColumns { get; set; }
|
public List<string> IgnoreColumns { get; set; }
|
||||||
public bool IsCount { get; set; }
|
public bool IsCount { get; set; }
|
||||||
@@ -641,6 +642,18 @@ namespace SqlSugar
|
|||||||
if (this.AsTables.Any(it=>it.Key==EntityName))
|
if (this.AsTables.Any(it=>it.Key==EntityName))
|
||||||
{
|
{
|
||||||
name = this.AsTables.FirstOrDefault(it => it.Key == EntityName).Value;
|
name = this.AsTables.FirstOrDefault(it => it.Key == EntityName).Value;
|
||||||
|
if (this.IsQueryInQuery && this.SelectValue != null && this.SelectValue is Expression)
|
||||||
|
{
|
||||||
|
if (this.SelectValue.ToString().Contains("Subqueryable()")&& name.TrimStart().StartsWith("("))
|
||||||
|
{
|
||||||
|
var oldName = name;
|
||||||
|
name = Regex.Match(name, @"\(.+\)").Value;
|
||||||
|
if (name.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
name = oldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var result = Builder.GetTranslationTableName(name);
|
var result = Builder.GetTranslationTableName(name);
|
||||||
result += UtilConstants.Space;
|
result += UtilConstants.Space;
|
||||||
|
|||||||
@@ -115,6 +115,19 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (type==DBNull.Value.GetType())
|
else if (type==DBNull.Value.GetType())
|
||||||
{
|
{
|
||||||
|
if (parameter.DbType.IsIn(System.Data.DbType.Int32))
|
||||||
|
{
|
||||||
|
sqlParameter.NpgsqlDbType = NpgsqlDbType.Integer | NpgsqlDbType.Array;
|
||||||
|
}
|
||||||
|
else if (parameter.DbType.IsIn(System.Data.DbType.Int64))
|
||||||
|
{
|
||||||
|
sqlParameter.NpgsqlDbType = NpgsqlDbType.Bigint | NpgsqlDbType.Array;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqlParameter.NpgsqlDbType =NpgsqlDbType.Text | NpgsqlDbType.Array;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -313,6 +313,28 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public override bool IsAnyTable(string tableName, bool isCache = true)
|
||||||
|
{
|
||||||
|
if (tableName.Contains("."))
|
||||||
|
{
|
||||||
|
var schemas = GetSchemas();
|
||||||
|
var first =this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').First());
|
||||||
|
var schemaInfo= schemas.FirstOrDefault(it=>it.EqualCase(first));
|
||||||
|
if (schemaInfo == null)
|
||||||
|
{
|
||||||
|
return base.IsAnyTable(tableName, isCache);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var result= this.Context.Ado.GetInt($"select object_id('{tableName}')");
|
||||||
|
return result > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return base.IsAnyTable(tableName, isCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
public List<string> GetSchemas()
|
public List<string> GetSchemas()
|
||||||
{
|
{
|
||||||
return this.Context.Ado.SqlQuery<string>("SELECT name FROM sys.schemas where name <> 'dbo'");
|
return this.Context.Ado.SqlQuery<string>("SELECT name FROM sys.schemas where name <> 'dbo'");
|
||||||
@@ -327,7 +349,14 @@ namespace SqlSugar
|
|||||||
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
||||||
{
|
{
|
||||||
sql = string.Format(this.DeleteTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()));
|
sql = string.Format(this.DeleteTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()));
|
||||||
sql = sql.Replace(",dbo,", $",{tableSchemas},").Replace("'user'", "'SCHEMA'");
|
if (tableSchemas.EqualCase("user"))
|
||||||
|
{
|
||||||
|
sql = sql.Replace("'user'", "'SCHEMA'").Replace("dbo", $"'{tableSchemas}'");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = sql.Replace(",dbo,", $",{tableSchemas},").Replace("'user'", "'SCHEMA'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
@@ -359,7 +388,14 @@ namespace SqlSugar
|
|||||||
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
||||||
{
|
{
|
||||||
sql = string.Format(this.AddTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()), description);
|
sql = string.Format(this.AddTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()), description);
|
||||||
sql = sql.Replace("N'dbo'", $"N'{tableSchemas}'").Replace("N'user'", "N'SCHEMA'");
|
if (tableSchemas.EqualCase("user"))
|
||||||
|
{
|
||||||
|
sql = sql.Replace("N'user', N'dbo'", $"N'user', '{tableSchemas}'").Replace("N'user'", "N'SCHEMA'");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = sql.Replace("N'dbo'", $"N'{tableSchemas}'").Replace("N'user'", "N'SCHEMA'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
var result= this.Context.Queryable<T>(queryable);
|
var result= this.Context.Queryable<T>(queryable);
|
||||||
var QueryBuilder = queryable.QueryBuilder;
|
var QueryBuilder = queryable.QueryBuilder;
|
||||||
|
result.QueryBuilder.IsQueryInQuery = true;
|
||||||
result.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex++;
|
result.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex++;
|
||||||
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++;
|
||||||
|
|||||||
Reference in New Issue
Block a user