Browse Source

Update Core

pull/18/head
sunkaixuan 3 years ago
parent
commit
4873576647
  1. 9
      Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 14
      Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs
  3. 3
      Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  4. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  5. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  6. 13
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  7. 13
      Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs
  8. 40
      Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs
  9. 1
      Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs

9
Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -366,7 +366,14 @@ namespace SqlSugar
{
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 properyTypeName = string.Empty;

14
Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/SplitCodeFirstProvider.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -16,6 +17,19 @@ namespace SqlSugar
}
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);
SplitTableContext helper = new SplitTableContext(Context)

3
Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -206,7 +206,8 @@ namespace SqlSugar
this.Context.Ado.ExecuteCommand(sql);
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 type = UtilMethods.GetUnderType(dtColumInfo.DataType);
var value= type==UtilConstants.StringType?(object)"": Activator.CreateInstance(type);

8
Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -203,6 +203,14 @@ namespace SqlSugar
object setValue = 0;
if (idValue > int.MaxValue)
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
setValue = Convert.ToInt32(idValue);
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);

1
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -2943,6 +2943,7 @@ namespace SqlSugar
_Size=it._Size
}).ToList();
}
asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery;
asyncQueryableBuilder.Includes = this.QueryBuilder.Includes;
asyncQueryableBuilder.Take = this.QueryBuilder.Take;
asyncQueryableBuilder.Skip = this.QueryBuilder.Skip;

13
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -33,6 +33,7 @@ namespace SqlSugar
#endregion
#region Splicing basic
public bool IsQueryInQuery { get; set; }
public List<object> Includes { get; set; }
public List<string> IgnoreColumns { get; set; }
public bool IsCount { get; set; }
@ -641,6 +642,18 @@ namespace SqlSugar
if (this.AsTables.Any(it=>it.Key==EntityName))
{
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);
result += UtilConstants.Space;

13
Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs

@ -115,6 +115,19 @@ namespace SqlSugar
}
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
{

40
Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs

@ -313,6 +313,28 @@ namespace SqlSugar
#endregion
#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()
{
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)))
{
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);
@ -359,7 +388,14 @@ namespace SqlSugar
if (schemas.Any(y => y.EqualCase(tableSchemas)))
{
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);

1
Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs

@ -346,6 +346,7 @@ namespace SqlSugar
var result= this.Context.Queryable<T>(queryable);
var QueryBuilder = queryable.QueryBuilder;
result.QueryBuilder.IsQueryInQuery = true;
result.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex++;
result.QueryBuilder.LambdaExpressions.ParameterIndex = QueryBuilder.LambdaExpressions.ParameterIndex++;
result.QueryBuilder.LambdaExpressions.Index = QueryBuilder.LambdaExpressions.Index++;

Loading…
Cancel
Save