@@ -665,6 +665,7 @@ public class SmDto
665665 }
666666
667667 // restrictions in which tables
668+ var restrictAAS = false ;
668669 var restrictSM = false ;
669670 var restrictSME = false ;
670671 var restrictSValue = false ;
@@ -673,6 +674,7 @@ public class SmDto
673674
674675 // restrict all tables seperate
675676 IQueryable < CombinedSMSMEV > comTable = null ;
677+ IQueryable < AASSet > ? aasTable ;
676678 IQueryable < SMSet > smTable ;
677679 IQueryable < SMESet > smeTable ;
678680 IQueryable < SValueSet > ? sValueTable ;
@@ -685,7 +687,8 @@ public class SmDto
685687 {
686688 string ? rawSQLEx ;
687689 // check restrictions
688- restrictSM = conditionsExpression . TryGetValue ( "sm" , out var value ) && value != "" && value != "true" ;
690+ restrictAAS = conditionsExpression . TryGetValue ( "aas" , out var value ) && value != "" && value != "true" ;
691+ restrictSM = conditionsExpression . TryGetValue ( "sm" , out value ) && value != "" && value != "true" ;
689692 restrictSME = conditionsExpression . TryGetValue ( "sme" , out value ) && value != "" && value != "true" ;
690693 restrictSValue = conditionsExpression . TryGetValue ( "svalue" , out value ) && value != "" && value != "true" ;
691694 restrictNValue = conditionsExpression . TryGetValue ( "nvalue" , out value ) && value != "" && value != "true" ;
@@ -1039,25 +1042,28 @@ public class SmDto
10391042 if ( ! skip )
10401043 {
10411044 // restrict all tables seperate
1045+ aasTable = db . AASSets ;
1046+ aasTable = restrictAAS ? aasTable . Where ( conditionsExpression [ "aas" ] ) : null ;
10421047 smTable = db . SMSets ;
10431048 smTable = restrictSM ? smTable . Where ( conditionsExpression [ "sm" ] ) : smTable ;
1044- if ( smRefId != null )
1045- {
1046- var smRefIdList = smRefId . ToList ( ) ;
1047- smTable = smTable . Where ( s => smRefIdList . Contains ( s . Id ) ) ;
1048- }
10491049 smeTable = restrictSME ? db . SMESets . Where ( conditionsExpression [ "sme" ] ) : db . SMESets ;
10501050 sValueTable = restrictValue ? ( restrictSValue ? db . SValueSets . Where ( conditionsExpression [ "svalue" ] ) : null ) : db . SValueSets ;
10511051 iValueTable = restrictValue ? ( restrictNValue ? db . IValueSets . Where ( conditionsExpression [ "nvalue" ] ) : null ) : db . IValueSets ;
10521052 dValueTable = restrictValue ? ( restrictNValue ? db . DValueSets . Where ( conditionsExpression [ "nvalue" ] ) : null ) : db . DValueSets ;
10531053
10541054 if ( consolidate )
10551055 {
1056- comTable = CombineTables ( direction , smTable , smeTable , sValueTable , iValueTable , dValueTable , false ) ;
1057- var x1 = comTable . Take ( 10 ) . ToList ( ) ;
1056+ comTable = CombineTables ( db , direction , aasTable , smTable , smeTable , sValueTable , iValueTable , dValueTable , false ) ;
1057+ // var x1 = comTable.Take(10).ToList();
10581058 }
10591059 else
10601060 {
1061+ if ( smRefId != null )
1062+ {
1063+ var smRefIdList = smRefId . ToList ( ) ;
1064+ smTable = smTable . Where ( s => smRefIdList . Contains ( s . Id ) ) ;
1065+ }
1066+
10611067 // combine tables to a raw sql
10621068 rawSQLEx = CombineTablesToRawSQL ( direction , smTable , smeTable , sValueTable , iValueTable , dValueTable , false ) ;
10631069 // table name needed for EXISTS in path search
@@ -1178,7 +1184,7 @@ public class SmDto
11781184 TimeStampTree = TimeStamp . TimeStamp . DateTimeToString ( c . SM_TimeStampTree ) ,
11791185 MatchPathList = null
11801186 } ) . Distinct ( ) ;
1181- var x2 = resultSM . Take ( 10 ) . ToList ( ) ;
1187+ // var x2 = resultSM.Take(10).ToList();
11821188 }
11831189
11841190 // select for count
@@ -2325,14 +2331,25 @@ public class UnifiedValue
23252331 }
23262332
23272333 private static IQueryable < CombinedSMSMEV > CombineTables (
2334+ AasContext db ,
23282335 int direction ,
2336+ IQueryable < AASSet > ? aasTable ,
23292337 IQueryable < SMSet > smTable ,
23302338 IQueryable < SMESet > smeTable ,
23312339 IQueryable < SValueSet > ? sValueTable ,
23322340 IQueryable < IValueSet > ? iValueTable ,
23332341 IQueryable < DValueSet > ? dValueTable ,
23342342 bool withParaWithoutValue )
23352343 {
2344+ if ( aasTable != null )
2345+ {
2346+ smTable = smTable
2347+ . Where ( sm =>
2348+ db . SMRefSets . Any ( r =>
2349+ r . Identifier == sm . Identifier &&
2350+ aasTable . Any ( a => a . Id == r . AASId ) ) ) ;
2351+ }
2352+
23362353 var filteredSM = smTable . Select ( sm => new
23372354 {
23382355 SM_Id = sm . Id ,
@@ -2343,7 +2360,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
23432360 SM_Identifier = sm . Identifier ,
23442361 SM_TimeStampTree = sm . TimeStampTree
23452362 } ) ;
2346- var x1 = filteredSM . Take ( 10 ) . ToList ( ) ;
2363+ // var x1 = filteredSM.Take(10).ToList();
23472364
23482365 var filteredSME = smeTable . Select ( sme => new
23492366 {
@@ -2357,7 +2374,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
23572374 SME_TimeStamp = sme . TimeStamp ,
23582375 SME_TValue = sme . TValue
23592376 } ) ;
2360- var x2 = filteredSME . Take ( 10 ) . ToList ( ) ;
2377+ // var x2 = filteredSME.Take(10).ToList();
23612378
23622379 IQueryable < UnifiedValue > allValues = null ;
23632380 // }) ?? Enumerable.Empty<UnifiedValue>().AsQueryable();
@@ -2370,7 +2387,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
23702387 if ( sValues != null )
23712388 {
23722389 allValues = sValues ;
2373- var x3 = sValues . Take ( 10 ) . ToList ( ) ;
2390+ // var x3 = sValues.Take(10).ToList();
23742391 }
23752392
23762393 var iValues = iValueTable ? . Select ( v => new UnifiedValue
@@ -2389,7 +2406,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
23892406 {
23902407 allValues = allValues . Concat ( iValues ) ;
23912408 }
2392- var x4 = iValues . Take ( 10 ) . ToList ( ) ;
2409+ // var x4 = iValues.Take(10).ToList();
23932410 }
23942411
23952412 var dValues = dValueTable ? . Select ( v => new UnifiedValue
@@ -2408,12 +2425,13 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
24082425 {
24092426 allValues = allValues . Concat ( dValues ) ;
24102427 }
2411- var x5 = dValues . Take ( 10 ) . ToList ( ) ;
2428+ // var x5 = dValues.Take(10).ToList();
24122429 }
24132430
2431+ var safeAllValues = allValues ?? Enumerable . Empty < UnifiedValue > ( ) . AsQueryable ( ) ;
24142432 if ( allValues != null )
24152433 {
2416- var x6 = allValues . Take ( 10 ) . ToList ( ) ;
2434+ // var x6 = allValues.Take(10).ToList();
24172435 }
24182436
24192437 IQueryable < CombinedSMSMEV > result ;
@@ -2424,9 +2442,9 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
24242442 sm => sm . SM_Id ,
24252443 sme => sme . SME_SMId ,
24262444 ( sm , sme ) => new { sm , sme } ) ;
2427- var x7 = smAndSme . Take ( 10 ) . ToList ( ) ;
2445+ // var x7 = smAndSme.Take(10).ToList();
24282446
2429- var joined = smAndSme . Join ( allValues ,
2447+ var joined = smAndSme . Join ( safeAllValues ,
24302448 sm_sme => sm_sme . sme . SME_Id ,
24312449 v => v . V_SMEId ,
24322450 ( sm_sme , v ) => new CombinedSMSMEV
@@ -2483,7 +2501,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
24832501 {
24842502 result = joined ;
24852503 }
2486- var x8 = result . Take ( 10 ) . ToList ( ) ;
2504+ // var x8 = result.Take(10).ToList();
24872505 }
24882506 else if ( direction == 1 ) // middle-out
24892507 {
@@ -2492,7 +2510,6 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
24922510 sm => sm . SM_Id ,
24932511 ( sme , sm ) => new { sm , sme } ) ;
24942512
2495- var safeAllValues = allValues ?? Enumerable . Empty < UnifiedValue > ( ) . AsQueryable ( ) ;
24962513 var joined = smeAndSm . Join ( safeAllValues ,
24972514 sm_sme => sm_sme . sme . SME_Id ,
24982515 v => v . V_SMEId ,
@@ -2553,7 +2570,7 @@ private static IQueryable<CombinedSMSMEV> CombineTables(
25532570 }
25542571 else // direction == 2, bottom-up
25552572 {
2556- var smeAndValue = allValues . Join ( filteredSME ,
2573+ var smeAndValue = safeAllValues . Join ( filteredSME ,
25572574 v => v . V_SMEId ,
25582575 sme => sme . SME_Id ,
25592576 ( v , sme ) => new { v , sme } ) ;
0 commit comments