mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-25 04:27:14 +08:00
Update Core
This commit is contained in:
@@ -261,7 +261,7 @@ namespace SqlSugar
|
||||
if (bindProperyTypeName.IsContainsIn("int", "int32"))
|
||||
method = isNullableType ? getConvertInt32 : getInt32;
|
||||
if (bindProperyTypeName.IsContainsIn("int64"))
|
||||
method = isNullableType ? getConvertInt64 : getInt64;
|
||||
method = null;
|
||||
if (bindProperyTypeName.IsContainsIn("byte"))
|
||||
method = isNullableType ? getConvertByte : getByte;
|
||||
if (bindProperyTypeName.IsContainsIn("int16"))
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace SqlSugar
|
||||
private bool IsAttribute { get; set; }
|
||||
private bool IsDefaultValue { get; set; }
|
||||
private Func<string, bool> WhereColumnsfunc;
|
||||
private Func<string, string> FormatFileNameFunc { get; set; }
|
||||
private bool IsStringNullable {get;set;}
|
||||
private ISqlBuilder SqlBuilder
|
||||
{
|
||||
get
|
||||
@@ -55,6 +57,11 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#region Setting Template
|
||||
public IDbFirst StringNullable()
|
||||
{
|
||||
IsStringNullable = true;
|
||||
return this;
|
||||
}
|
||||
public IDbFirst SettingClassDescriptionTemplate(Func<string, string> func)
|
||||
{
|
||||
this.ClassDescriptionTemplate = func(this.ClassDescriptionTemplate);
|
||||
@@ -137,6 +144,7 @@ namespace SqlSugar
|
||||
Check.Exception(true, ErrorMessage.GetThrowMessage("Need to achieve ConnectionConfig.ConfigureExternal Services.RazorService", "需要实现 ConnectionConfig.ConfigureExternal Services.RazorService接口"));
|
||||
}
|
||||
this.Context.Utilities.RemoveCacheAll();
|
||||
result.FormatFileNameFunc = this.FormatFileNameFunc;
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
@@ -147,6 +155,11 @@ namespace SqlSugar
|
||||
this.IsAttribute = isCreateAttribute;
|
||||
return this;
|
||||
}
|
||||
public IDbFirst FormatFileName(Func<string, string> formatFileNameFunc)
|
||||
{
|
||||
this.FormatFileNameFunc = formatFileNameFunc;
|
||||
return this;
|
||||
}
|
||||
public IDbFirst IsCreateDefaultValue(bool isCreateDefaultValue = true)
|
||||
{
|
||||
this.IsDefaultValue = isCreateDefaultValue;
|
||||
@@ -319,7 +332,12 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in classStringList)
|
||||
{
|
||||
var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs", item.Key);
|
||||
var fileName = item.Key;
|
||||
if (FormatFileNameFunc!= null)
|
||||
{
|
||||
fileName = FormatFileNameFunc(fileName);
|
||||
}
|
||||
var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs", fileName);
|
||||
FileHelper.CreateFile(filePath, item.Value, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
@@ -410,12 +428,16 @@ namespace SqlSugar
|
||||
}
|
||||
if (result == "Int32")
|
||||
{
|
||||
result = "int";
|
||||
result = item.IsNullable?"int?":"int";
|
||||
}
|
||||
if (result == "String")
|
||||
{
|
||||
result = "string";
|
||||
}
|
||||
if (result == "string" && item.IsNullable && IsStringNullable)
|
||||
{
|
||||
result = result + "?";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string GetPropertyTypeConvert(DbColumnInfo item)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SqlSugar
|
||||
public class RazorFirst
|
||||
{
|
||||
internal List<KeyValuePair<string,string>> ClassStringList { get; set; }
|
||||
internal Func<string, string> FormatFileNameFunc { get; set; }
|
||||
|
||||
public static string DefaultRazorClassTemplate =
|
||||
@"using System;
|
||||
@@ -79,7 +80,12 @@ namespace @Model.Namespace
|
||||
{
|
||||
foreach (var item in ClassStringList)
|
||||
{
|
||||
var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs", item.Key);
|
||||
var fileName = item.Key;
|
||||
if (this.FormatFileNameFunc != null)
|
||||
{
|
||||
fileName = this.FormatFileNameFunc(fileName);
|
||||
}
|
||||
var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs",fileName);
|
||||
FileHelper.CreateFile(filePath, item.Value, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1123,16 +1123,28 @@ 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 = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(primaryKeyValue);
|
||||
var tableName= this.QueryBuilder.GetTableNameString;
|
||||
if (this.QueryBuilder.IsSingle() == false)
|
||||
{
|
||||
if (this.QueryBuilder.JoinQueryInfos.Count>0)
|
||||
{
|
||||
tableName = this.QueryBuilder.JoinQueryInfos.First().TableName;
|
||||
}
|
||||
if (this.QueryBuilder.EasyJoinInfos.Count>0)
|
||||
{
|
||||
tableName = this.QueryBuilder.JoinQueryInfos.First().TableName;
|
||||
}
|
||||
}
|
||||
var current = this.Context.Queryable<T>().AS(tableName).InSingle(primaryKeyValue);
|
||||
if (current != null)
|
||||
{
|
||||
result.Add(current);
|
||||
object parentId = ParentInfo.PropertyInfo.GetValue(current,null);
|
||||
int i = 0;
|
||||
while (parentId!=null&&this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).In(parentId).Any())
|
||||
while (parentId!=null&&this.Context.Queryable<T>().AS(tableName).In(parentId).Any())
|
||||
{
|
||||
Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限(100),检查最顶层的ParentId是否是null或者0"));
|
||||
var parent = this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingle(parentId);
|
||||
var parent = this.Context.Queryable<T>().AS(tableName).InSingle(parentId);
|
||||
result.Add(parent);
|
||||
parentId= ParentInfo.PropertyInfo.GetValue(parent, null);
|
||||
++i;
|
||||
@@ -1148,16 +1160,28 @@ 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>().AS(this.QueryBuilder.GetTableNameString).InSingleAsync(primaryKeyValue);
|
||||
var tableName = this.QueryBuilder.GetTableNameString;
|
||||
if (this.QueryBuilder.IsSingle() == false)
|
||||
{
|
||||
if (this.QueryBuilder.JoinQueryInfos.Count > 0)
|
||||
{
|
||||
tableName = this.QueryBuilder.JoinQueryInfos.First().TableName;
|
||||
}
|
||||
if (this.QueryBuilder.EasyJoinInfos.Count > 0)
|
||||
{
|
||||
tableName = this.QueryBuilder.JoinQueryInfos.First().TableName;
|
||||
}
|
||||
}
|
||||
var current =await this.Context.Queryable<T>().AS(tableName).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>().AS(this.QueryBuilder.GetTableNameString).In(parentId).AnyAsync())
|
||||
while (parentId != null &&await this.Context.Queryable<T>().AS(tableName).In(parentId).AnyAsync())
|
||||
{
|
||||
Check.Exception(i > 100, ErrorMessage.GetThrowMessage("Dead cycle", "出现死循环或超出循环上限(100),检查最顶层的ParentId是否是null或者0"));
|
||||
var parent =await this.Context.Queryable<T>().AS(this.QueryBuilder.GetTableNameString).InSingleAsync(parentId);
|
||||
var parent =await this.Context.Queryable<T>().AS(tableName).InSingleAsync(parentId);
|
||||
result.Add(parent);
|
||||
parentId = ParentInfo.PropertyInfo.GetValue(parent, null);
|
||||
++i;
|
||||
|
||||
@@ -652,7 +652,7 @@ namespace SqlSugar
|
||||
result = result.Replace(" ) unionTable ", ") "+TableShortName + UtilConstants.Space);
|
||||
TableShortName = null;
|
||||
}
|
||||
if (this.TableShortName.HasValue())
|
||||
if (this.TableShortName.HasValue()&&!IsSqlQuery)
|
||||
{
|
||||
result += (TableShortName + UtilConstants.Space);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,9 @@ namespace SqlSugar
|
||||
OldDbColumnName = item.OldDbColumnName,
|
||||
OracleSequenceName = item.OracleSequenceName,
|
||||
PropertyInfo = item.PropertyInfo,
|
||||
PropertyName = item.PropertyName
|
||||
PropertyName = item.PropertyName,
|
||||
IsArray=item.IsArray,
|
||||
IsJson=item.IsJson
|
||||
};
|
||||
columns.Add(item);
|
||||
}
|
||||
|
||||
@@ -547,6 +547,14 @@ namespace SqlSugar
|
||||
{
|
||||
parameter.CommonTempData = DateTime.Now.Date;
|
||||
}
|
||||
else if (item is ConditionalExpression)
|
||||
{
|
||||
parameter.CommonTempData = GetNewExpressionValue(item);
|
||||
}
|
||||
else if (IsNot(item))
|
||||
{
|
||||
parameter.CommonTempData = GetNewExpressionValue(item);
|
||||
}
|
||||
else if (IsDateDate(item))
|
||||
{
|
||||
parameter.CommonTempData = GetNewExpressionValue(item);
|
||||
@@ -585,7 +593,7 @@ namespace SqlSugar
|
||||
methodCallExpressionArgs.IsMember = false;
|
||||
}
|
||||
}
|
||||
if (IsDateDate(item) || IsDateValue(item)|| IsDateItemValue(item))
|
||||
if (IsDateDate(item) || IsDateValue(item) || IsDateItemValue(item) || item is ConditionalExpression||IsNot(item))
|
||||
{
|
||||
methodCallExpressionArgs.IsMember = true;
|
||||
}
|
||||
@@ -608,6 +616,11 @@ namespace SqlSugar
|
||||
parameter.ChildExpression = null;
|
||||
}
|
||||
|
||||
private static bool IsNot(Expression item)
|
||||
{
|
||||
return item is UnaryExpression && (item as UnaryExpression).NodeType == ExpressionType.Not;
|
||||
}
|
||||
|
||||
private bool IsDateItemValue(Expression item)
|
||||
{
|
||||
var result = false;
|
||||
|
||||
@@ -23,5 +23,7 @@ namespace SqlSugar
|
||||
void CreateClassFile(string directoryPath, string nameSpace = "Models");
|
||||
Dictionary<string, string> ToClassStringList(string nameSpace = "Models");
|
||||
void Init();
|
||||
IDbFirst FormatFileName(Func<string,string> formatFileNameFunc);
|
||||
IDbFirst StringNullable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,25 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\AdoProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\AopProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\CacheProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\CodeFirstProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\DbBindProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\DbFirstProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\DbMaintenanceProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\DeleteProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\EntityMaintenance\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\ExpressionableProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\FastestProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\FilterProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\InsertableProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\QueryableProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\Reportable\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\SaveableProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\SqlBuilderProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\SugarProvider\" />
|
||||
<Folder Include="Abstract\AdoProvider\Abstract\UpdateProvider\" />
|
||||
<Folder Include="Abstract\QueryableProvider\QueryableProvider\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user