!98 1.导航特性Navigate添加QueryPropertyNames属性,用于查询指定列

Merge pull request !98 from dangzhenjiuhao/master
This commit is contained in:
阿妮亚
2025-10-15 04:06:42 +00:00
committed by Gitee
2 changed files with 54 additions and 6 deletions

View File

@@ -271,7 +271,11 @@ namespace SqlSugar
var sql = GetWhereSql(GetCrossDatabase(abDb, bEntity));
if (sql.SelectString == null)
{
//加载指定列
var manualPropertyNames = GetQueryPropertyNames(navObjectNamePropety);
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(navObjectNamePropety);
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(navObjectNamePropety);
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(navObjectNamePropety);
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,23 @@ 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(System.Reflection.PropertyInfo navObjectNamePropety)
{
string[] queryPropertyNames = null;
if (navObjectNamePropety != null)
{
var navAttr = navObjectNamePropety.GetCustomAttribute<Navigate>();
if (navAttr != null && navAttr.QueryPropertyNames != null && navAttr.QueryPropertyNames.Length > 0)
{
queryPropertyNames = navAttr.QueryPropertyNames;
}
}
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;
}
}