Browse Source

Update .net core project

SqlSugar5
sunkaixuan 2 years ago
parent
commit
e93f056230
  1. 9
      Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs
  3. 11
      Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs
  4. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  5. 6
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs
  6. 1
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs
  7. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs
  8. 4
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

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

@ -221,12 +221,19 @@ namespace SqlSugar
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);
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle)
{
value = columnInfo.DefaultValue;
if (value.Equals(""))
{
value = "empty";
}
}
var dt = new Dictionary<string, object>();
dt.Add(columnInfo.DbColumnName, value);
this.Context.Updateable(dt)
.AS(tableName)
.Where($"{columnInfo.DbColumnName} is null ").ExecuteCommand();
if(this.Context.CurrentConnectionConfig.DbType!=DbType.Oracle)
columnInfo.IsNullable = false;
UpdateColumn(tableName, columnInfo);
}

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

@ -327,6 +327,7 @@ namespace SqlSugar
{
var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name);
var navList = selector(this.Context.Queryable<object>().AS(navEntityInfo.DbTableName)
.WhereIF(navObjectNameColumnInfo.Navigat.WhereSql.HasValue(), navObjectNameColumnInfo.Navigat.WhereSql)
.WhereIF(sqlObj.WhereString.HasValue(),sqlObj.WhereString)
.AddParameters(sqlObj.Parameters).Where(conditionalModels));
var groupQuery = (from l in list

11
Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs

@ -228,6 +228,7 @@ namespace SqlSugar
public string MappingAId { get; set; }
public string MappingBId { get; set; }
public NavigateType NavigatType { get; set; }
public string WhereSql { get; set; }
public Navigate(NavigateType navigatType,string name)
{
this.Name = name;
@ -239,6 +240,16 @@ namespace SqlSugar
this.Name2 = lastName;
this.NavigatType = navigatType;
}
public Navigate(NavigateType navigatType, string firstName, string lastName,string whereSql)
{
this.Name = firstName;
this.Name2 = lastName;
this.NavigatType = navigatType;
this.WhereSql = whereSql;
Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
}
public Navigate(Type MappingTableType,string typeAiD,string typeBId)
{
this.MappingType = MappingTableType;

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -12,11 +12,11 @@ namespace SqlSugar
{
if (model.Args.Count == 1)
{
return $"row_number() over(order by {model.Args[0].MemberName})";
return $"row_number() over(order by {model.Args[0].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
else
{
return $"row_number() over( partition by {model.Args[1].MemberName} order by {model.Args[0].MemberName})";
return $"row_number() over( partition by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[0].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})";
}
}
public virtual string RowCount(MethodCallExpressionModel model)

6
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -178,7 +178,11 @@ namespace SqlSugar
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
var name = (mappingInfo == null ? entityName : mappingInfo.DbTableName);
if (name.Contains("."))
if (name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight))
{
return name;
}
else if (name.Contains("."))
{
return string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight));
}

1
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs

@ -98,6 +98,7 @@ namespace SqlSugar
selectName = queryable.QueryBuilder.Builder.GetTranslationColumnName(selectName);
mapper.Sql = queryable
.AS(this.ProPertyEntity.DbTableName)
.WhereIF(Navigat.WhereSql.HasValue(),Navigat.WhereSql)
.Where($" {ShorName}.{name}={pk} ").Select(selectName).ToSql().Key;
mapper.Sql = $" ({mapper.Sql}) ";
return mapper;

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs

@ -66,6 +66,10 @@ namespace SqlSugar
var navColum = item.ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.Nav.Name);
Check.ExceptionEasy(pkColumn == null, $"{item.ThisEntityInfo.EntityName} need PrimayKey", $"使用导航属性{item.ThisEntityInfo.EntityName} 缺少主键");
var on = $" {ToShortName(shortName)}.{queryable.SqlBuilder.GetTranslationColumnName(pkColumn.DbColumnName)}={ToShortName(formInfo.ThisEntityInfo.DbTableName + (i - 1))}.{queryable.SqlBuilder.GetTranslationColumnName(navColum.DbColumnName)}";
if (item.Nav.WhereSql.HasValue())
{
on = (on + " AND " + item.Nav.WhereSql);
}
queryable.AddJoinInfo(item.ThisEntityInfo.DbTableName,ToShortName(shortName), on, JoinType.Inner);
++i;
lastShortName = shortName;

4
Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

@ -589,6 +589,10 @@ namespace SqlSugar
{
return Convert.ToInt32(item.FieldValue);
}
else if (item.FieldValue!=null&&item.CSharpTypeName.EqualCase(UtilConstants.BoolType.Name))
{
return Convert.ToBoolean(item.FieldValue.ToLower());
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name))
{
return Convert.ToInt64(item.FieldValue);

Loading…
Cancel
Save