Compare commits

...

7 Commits

Author SHA1 Message Date
sunkaixuan
6fdfb7bf8f Update 达梦 2025-10-15 15:47:59 +08:00
sunkaixuan
f823160bf8 Update nav query 2025-10-15 13:16:28 +08:00
sunkaixuan
29f377d7ed Update navquery 2025-10-15 12:38:47 +08:00
sunkaixuan
3a857c286c Merge branch 'master' of gitee.com:dotnetchina/SqlSugar 2025-10-15 12:16:27 +08:00
阿妮亚
503f4da6a7 !98 1.导航特性Navigate添加QueryPropertyNames属性,用于查询指定列
Merge pull request !98 from dangzhenjiuhao/master
2025-10-15 04:06:42 +00:00
sunkaixuan
4cf75745fd Update 达梦 2025-10-14 15:17:20 +08:00
dangzhenjiuhao
1882164dc9 1.导航特性Navigate添加QueryPropertyNames属性,用于查询指定列
2.NavigatManager<T>实现类的OneToOne、OneToMany、ManyToMany方法中获取列时添加过滤条件
2025-10-13 19:05:49 +08:00
4 changed files with 89 additions and 15 deletions

View File

@@ -106,28 +106,29 @@ namespace SqlSugar
Type mappingTableType = navigate.MappingType;
string typeAiD = navigate.MappingAId;
string typeBId = navigate.MappingBId;
var queryPropertyNames = navigate.QueryPropertyNames;
ConstructorInfo constructor;
object[] constructorArgs;
if (mappingTableType != null && typeAiD != null && typeBId != null)
{
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(Type), typeof(string), typeof(string), typeof(string) });
constructorArgs = new object[] { mappingTableType, typeAiD, typeBId, whereSql };
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(Type), typeof(string), typeof(string), typeof(string), typeof(string[]) });
constructorArgs = new object[] { mappingTableType, typeAiD, typeBId, whereSql , queryPropertyNames };
}
else if (!string.IsNullOrEmpty(whereSql))
{
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string) });
constructorArgs = new object[] { navigatType, name, name2, whereSql };
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string), typeof(string[]) });
constructorArgs = new object[] { navigatType, name, name2, whereSql, queryPropertyNames };
}
else if (!string.IsNullOrEmpty(name2))
{
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string) });
constructorArgs = new object[] { navigatType, name, name2 };
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string[]) });
constructorArgs = new object[] { navigatType, name, name2, queryPropertyNames };
}
else
{
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string) });
constructorArgs = new object[] { navigatType, name };
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string[]) });
constructorArgs = new object[] { navigatType, name, queryPropertyNames };
}
return new CustomAttributeBuilder(constructor, constructorArgs);

View File

@@ -271,7 +271,11 @@ namespace SqlSugar
var sql = GetWhereSql(GetCrossDatabase(abDb, bEntity));
if (sql.SelectString == null)
{
//加载指定列
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
var columns = bEntityInfo.Columns.Where(it => !it.IsIgnore)
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
.Select(it => GetOneToManySelectByColumnInfo(it, abDb)).ToList();
sql.SelectString = String.Join(",", columns);
}
@@ -433,7 +437,11 @@ namespace SqlSugar
var sqlObj = GetWhereSql(db, navObjectNameColumnInfo.Navigat.Name);
if (sqlObj.SelectString == null)
{
// 加载指定列
var queryPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
.WhereIF(queryPropertyNames != null && queryPropertyNames.Length > 0, it => queryPropertyNames.Contains(it.PropertyName))
.Select(it => GetOneToOneSelectByColumnInfo(it, db)).ToList();
sqlObj.SelectString = String.Join(",", columns);
}
@@ -581,7 +589,10 @@ namespace SqlSugar
{
if (sqlObj.SelectString == null)
{
//加载指定列
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
.Select(it => GetOneToManySelectByColumnInfo(it, childDb)).ToList();
sqlObj.SelectString = String.Join(",", columns);
}
@@ -699,7 +710,11 @@ namespace SqlSugar
{
if (sqlObj.SelectString == null)
{
//加载指定列
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
.Select(it => GetOneToManySelectByColumnInfo(it,childDb)).ToList();
sqlObj.SelectString = String.Join(",", columns);
}
@@ -1252,5 +1267,38 @@ namespace SqlSugar
return QueryBuilder.Builder.GetTranslationColumnName(it.DbColumnName) + " AS " + QueryBuilder.Builder.GetTranslationColumnName(it.PropertyName);
}
/// <summary>
/// 获取查询的属性名称列表
/// </summary>
/// <param name="navObjectNamePropety"></param>
/// <returns></returns>
private string[] GetQueryPropertyNames(EntityColumnInfo navObjectNameColumnInfo)
{
string[] queryPropertyNames = null;
if (navObjectNameColumnInfo?.Navigat?.QueryPropertyNames?.Any()==true)
{
var navInfo = navObjectNameColumnInfo?.Navigat;
queryPropertyNames = navObjectNameColumnInfo.Navigat.QueryPropertyNames;
var list = queryPropertyNames.ToList();
if (navInfo.AClassId != null)
{
list.Add(navInfo.AClassId);
}
if (navInfo.BClassId != null)
{
list.Add(navInfo.BClassId);
}
if (navInfo.Name != null)
{
list.Add(navInfo.Name);
}
if (navInfo.Name2 != null)
{
list.Add(navInfo.Name2);
}
queryPropertyNames = list.ToArray();
}
return queryPropertyNames;
}
}
}

View File

@@ -243,6 +243,15 @@ namespace SqlSugar
internal string BClassId { get; set; }
/// <summary>
/// 用于查询指定列
/// </summary>
internal string[] QueryPropertyNames { get; set; }
public string[] GetQueryPropertyNames()
{
return QueryPropertyNames;
}
public string GetName()
{
return Name;
@@ -272,36 +281,40 @@ namespace SqlSugar
{
return WhereSql;
}
public Navigate(NavigateType navigatType,string ifSingleMasterTableColumn_IfListChildTableColumn)
public Navigate(NavigateType navigatType,string ifSingleMasterTableColumn_IfListChildTableColumn, string[] queryPropertyNames = null)
{
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
this.NavigatType = navigatType;
this.QueryPropertyNames = queryPropertyNames;
}
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn)
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string[] queryPropertyNames = null)
{
Check.ExceptionEasy(navigatType == NavigateType.ManyToMany, "Correct usage [Navigate(typeof(ABMapping), nameof(abmapping.aid), nameof(abmapp.bid))], incorrect usage: [Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]", "多对多第一个参数是Type不是NavigateType正确用法[Navigate(typeof(ABMapping), nameof(ABMapping.Aid), nameof(ABMapping.BId))],错误用法:[Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]");
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
this.NavigatType = navigatType;
this.QueryPropertyNames = queryPropertyNames;
}
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string whereSql)
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string whereSql, string[] queryPropertyNames = null)
{
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
this.NavigatType = navigatType;
this.WhereSql = whereSql;
this.QueryPropertyNames = queryPropertyNames;
//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)
public Navigate(Type MappingTableType,string typeAId,string typeBId, string[] queryPropertyNames = null)
{
this.MappingType = MappingTableType;
this.MappingAId = typeAId;
this.MappingBId = typeBId;
this.NavigatType = NavigateType.ManyToMany;
this.QueryPropertyNames = queryPropertyNames;
}
public Navigate(Type MappingTableType, string mappingAId, string mappingBId,string aClassId,string bClassId)
public Navigate(Type MappingTableType, string mappingAId, string mappingBId,string aClassId,string bClassId, string[] queryPropertyNames = null)
{
this.MappingType = MappingTableType;
this.MappingAId = mappingAId;
@@ -309,14 +322,16 @@ namespace SqlSugar
this.AClassId = aClassId;
this.BClassId = bClassId;
this.NavigatType = NavigateType.ManyToMany;
this.QueryPropertyNames = queryPropertyNames;
}
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql)
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql, string[] queryPropertyNames = null)
{
this.MappingType = MappingTableType;
this.MappingAId = typeAiD;
this.MappingBId = typeBId;
this.NavigatType = NavigateType.ManyToMany;
this.WhereSql+= mappingSql;
this.QueryPropertyNames = queryPropertyNames;
}
}

View File

@@ -205,7 +205,7 @@ namespace SqlSugar
return sqlParameter.Direction == ParameterDirection.Output && this.CommandType == CommandType.StoredProcedure;
}
private static string[] KeyWord =new string []{ ":asc", "@asc", ":desc", "@desc","@month", ":month", ":day","@day","@group", ":group",":index", "@index", "@order", ":order", "@user", "@level", ":user", ":level",":type","@type", ":year", "@year" };
private static string[] KeyWord =new string []{ ":asc", "@asc", ":desc", "@desc","@month", ":month", ":day","@day","@group", ":group",":index", "@index", "@order", ":order", "@user", "@level", ":user", ":level",":type","@type", ":year", "@year" };
private static string ReplaceKeyWordParameterName(string sql, SugarParameter[] parameters)
{
sql = ReplaceKeyWordWithAd(sql, parameters);
@@ -230,13 +230,23 @@ namespace SqlSugar
{
if (parameters != null && sql != null && sql.Contains("@"))
{
var isSelectIdentity = sql.EndsWith(";select @@identity")&&sql.StartsWith("INSERT INTO ");
foreach (var item in parameters.OrderByDescending(it => it.ParameterName.Length))
{
if (item.ParameterName.StartsWith("@"))
{
item.ParameterName = ":" + item.ParameterName.TrimStart('@');
}
var paraNameIsIdentity = isSelectIdentity && item.ParameterName.EqualCase(":Identity");
if (paraNameIsIdentity)
{
sql = sql.Replace(";select @@identity", "");
}
sql = Regex.Replace(sql, "@" + item.ParameterName.TrimStart(':'), item.ParameterName, RegexOptions.IgnoreCase);
if (paraNameIsIdentity)
{
sql = sql+";select @@identity";
}
}
}