@@ -893,25 +893,20 @@ internal static T LoadSingleById<T>(this IDbCommand dbCmd, object value, string[
893
893
return row ;
894
894
}
895
895
896
- public static void LoadReferences < T > ( this IDbCommand dbCmd , T instance , string [ ] include = null )
896
+ public static void LoadReferences < T > ( this IDbCommand dbCmd , T instance , IEnumerable < string > include = null )
897
897
{
898
898
var loadRef = new LoadReferencesSync < T > ( dbCmd , instance ) ;
899
899
var fieldDefs = loadRef . FieldDefs ;
900
900
901
- if ( include != null )
902
- {
903
- // Check that any include values aren't reference fields of the specified type
904
- var includeLower = include . Map ( x => x . ToLower ( ) ) ;
905
- var fieldNames = fieldDefs . ConvertAll ( q => q . FieldName . ToLower ( ) ) ;
906
- var invalid = includeLower . Except ( fieldNames ) . ToList ( ) ;
907
- if ( invalid . Count > 0 )
908
- throw new ArgumentException ( "Fields '{0}' are not Reference Properties of Type '{1}'" . Fmt ( invalid . Join ( "', '" ) , typeof ( T ) . Name ) ) ;
909
-
910
- fieldDefs = fieldDefs . Where ( f => includeLower . Contains ( f . FieldName . ToLower ( ) ) ) . ToList ( ) ;
911
- }
901
+ var includeSet = include != null
902
+ ? new HashSet < string > ( include , StringComparer . OrdinalIgnoreCase )
903
+ : null ;
912
904
913
905
foreach ( var fieldDef in fieldDefs )
914
906
{
907
+ if ( includeSet != null && ! includeSet . Contains ( fieldDef . Name ) )
908
+ continue ;
909
+
915
910
dbCmd . Parameters . Clear ( ) ;
916
911
var listInterface = fieldDef . FieldType . GetTypeWithGenericInterfaceOf ( typeof ( IList < > ) ) ;
917
912
if ( listInterface != null )
@@ -925,25 +920,20 @@ public static void LoadReferences<T>(this IDbCommand dbCmd, T instance, string[]
925
920
}
926
921
}
927
922
928
- internal static List < Into > LoadListWithReferences < Into , From > ( this IDbCommand dbCmd , SqlExpression < From > expr = null , string [ ] include = null )
923
+ internal static List < Into > LoadListWithReferences < Into , From > ( this IDbCommand dbCmd , SqlExpression < From > expr = null , IEnumerable < string > include = null )
929
924
{
930
925
var loadList = new LoadListSync < Into , From > ( dbCmd , expr ) ;
931
-
932
926
var fieldDefs = loadList . FieldDefs ;
933
- if ( include != null )
934
- {
935
- // Check that any include values aren't reference fields of the specified From type
936
- var includeLower = include . Map ( x => x . ToLower ( ) ) ;
937
- var fieldNames = fieldDefs . ConvertAll ( q => q . FieldName . ToLower ( ) ) ;
938
- var invalid = includeLower . Except ( fieldNames ) . ToList ( ) ;
939
- if ( invalid . Count > 0 )
940
- throw new ArgumentException ( "Fields '{0}' are not Reference Properties of Type '{1}'" . Fmt ( invalid . Join ( "', '" ) , typeof ( From ) . Name ) ) ;
941
-
942
- fieldDefs = fieldDefs . Where ( f => includeLower . Contains ( f . FieldName . ToLower ( ) ) ) . ToList ( ) ;
943
- }
927
+
928
+ var includeSet = include != null
929
+ ? new HashSet < string > ( include , StringComparer . OrdinalIgnoreCase )
930
+ : null ;
944
931
945
932
foreach ( var fieldDef in fieldDefs )
946
933
{
934
+ if ( includeSet != null && ! includeSet . Contains ( fieldDef . Name ) )
935
+ continue ;
936
+
947
937
var listInterface = fieldDef . FieldType . GetTypeWithGenericInterfaceOf ( typeof ( IList < > ) ) ;
948
938
if ( listInterface != null )
949
939
{
0 commit comments