internal static async Task <List <Into> > LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null, IEnumerable <string> include = null, CancellationToken token = default) { var loadList = new LoadListAsync <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) { await loadList.SetRefFieldListAsync(fieldDef, listInterface.GetGenericArguments()[0], token).ConfigAwait(); } else if (fieldDef.FieldReference != null) { await loadList.SetFieldReferenceAsync(fieldDef, fieldDef.FieldReference, token).ConfigAwait(); } else { await loadList.SetRefFieldAsync(fieldDef, fieldDef.FieldType, token).ConfigAwait(); } } return(loadList.ParentResults); }
internal static async Task <List <Into> > LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null, string[] include = null, CancellationToken token = default(CancellationToken)) { var loadList = new LoadListAsync <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 '{invalid.Join("', '")}' are not Reference Properties of Type '{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) { await loadList.SetRefFieldListAsync(fieldDef, listInterface.GenericTypeArguments()[0], token); } else { await loadList.SetRefFieldAsync(fieldDef, fieldDef.FieldType, token); } } return(loadList.ParentResults); }
internal static async Task <List <Into> > LoadListWithReferences <Into, From>(this IDbCommand dbCmd, SqlExpression <From> expr = null, CancellationToken token = default(CancellationToken)) { var loadList = new LoadListAsync <Into, From>(dbCmd, expr); foreach (var fieldDef in loadList.FieldDefs) { var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>)); if (listInterface != null) { await loadList.SetRefFieldListAsync(fieldDef, listInterface.GenericTypeArguments()[0], token); } else { await loadList.SetRefFieldAsync(fieldDef, fieldDef.FieldType, token); } } return(loadList.ParentResults); }