Sorry, haven't had my coffee yet. Just realized that's an ambiguous signature. We have to name the extension method something else like IncludeMany.
public static void IncludeMany<T>(this IFetchOptions<T> fetchOptions, string includeProperties)
{
if (string.IsNullOrWhiteSpace(includeProperties)) return;
ParseIncludeProperties(includeProperties)
.ForEach(x => fetchOptions.Include(x));
}
private static IEnumerable<string> ParseIncludeProperties(string includeProperties)
{
return includeProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
var entityData = await _unitOfWork.Entities.FindAsync(SetPredicate(), T => T.OrderBySelector(sortSelector),
options => options.IncludeMany(includeProperties));
Or better yet, ditch the comma separated list and go with an IEnumerable. You probably already have an IEnumerable from which you currently build the comma separated list.
public static void Include<T>(this IFetchOptions<T> fetchOptions, IEnumerable<string> properties)
{
properties.ForEach(x => fetchOptions.Include(x));
}
var properties = new [] { "A", "B", "C" };
var entityData = await _unitOfWork.Entities.FindAsync(SetPredicate(), T => T.OrderBySelector(sortSelector),
options => options.Include(properties ));
Edited by mgood - 20-Dec-2012 at 9:39am