internal static List <Into> LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null, string[] include = null)
        {
            var loadList = new LoadListSync <Into, From>(dbCmd, expr);

            var fieldDefs = loadList.FieldDefs;

            if (!include.IsEmpty())
            {
                // Check that any include values aren't reference fields of the specified From type
                var fields  = fieldDefs.Select(q => q.FieldName);
                var invalid = include.Except <string>(fields).ToList();
                if (invalid.Count > 0)
                {
                    throw new ArgumentException("Fields '{0}' are not Reference Properties of Type '{1}'".Fmt(invalid.Join("', '"), typeof(From).Name));
                }

                fieldDefs = loadList.FieldDefs.Where(fd => include.Contains(fd.FieldName)).ToList();
            }

            foreach (var fieldDef in fieldDefs)
            {
                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadList.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadList.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }

            return(loadList.ParentResults);
        }
        internal static List <Into> LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null, IEnumerable <string> include = null)
        {
            var loadList  = new LoadListSync <Into, From>(dbCmd, expr);
            var fieldDefs = loadList.FieldDefs;

            var includeSet = include != null
                ? new HashSet <string>(include, StringComparer.OrdinalIgnoreCase)
                : null;

            foreach (var fieldDef in fieldDefs)
            {
                if (includeSet != null && !includeSet.Contains(fieldDef.Name))
                {
                    continue;
                }

                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadList.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadList.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }

            return(loadList.ParentResults);
        }
        internal static List <Into> LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null)
        {
            var loadList = new LoadListSync <Into, From>(dbCmd, expr);

            foreach (var fieldDef in loadList.FieldDefs)
            {
                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadList.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadList.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }

            return(loadList.ParentResults);
        }