diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs index 30f9658364cc13b66916f6d52f3e4b32392f53d3..487134c8244d30efea90c8582406e1e9d15db966 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs @@ -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); } + /// + /// 获取查询的属性名称列表 + /// + /// + /// + private string[] GetQueryPropertyNames(System.Reflection.PropertyInfo navObjectNamePropety) + { + string[] queryPropertyNames = null; + if (navObjectNamePropety != null) + { + var navAttr = navObjectNamePropety.GetCustomAttribute(); + if (navAttr != null && navAttr.QueryPropertyNames != null && navAttr.QueryPropertyNames.Length > 0) + { + queryPropertyNames = navAttr.QueryPropertyNames; + } + } + return queryPropertyNames; + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index bf6657e5f8ec945863f5ec80e06a7223a8e64b40..1e7dce3f1ae1e0a1cdda2fde6e841a42ae306fe9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -243,6 +243,15 @@ namespace SqlSugar internal string BClassId { get; set; } + /// + /// 用于查询指定列 + /// + 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; } }