I'm attempting to convert a C# lambda that I've used many times to VB.Net, but I can't seem to figure out the correct syntax to use. Here is the original C# code:
public override IQueryable<E> Select<E>(params System.Linq.Expressions.Expression<Func<E, object>>[] includeExpressions)
{
IQueryable<E> result = null;
if (includeExpressions.Any())
{
result = includeExpressions.Aggregate<Expression<Func<E, object>>, IQueryable<E>>(Context.Set<E>(), (current, expression) => current.Include(expression));
}
return result;
}
I've used an online code converter and also attempted to re-write the function myself, but I'm not getting anywhere. This is what the code converter outputs when I provide the previous method:
Public Overrides Function [Select](Of E As Class)(ParamArray includeExpressions As Expression(Of Func(Of E, Object))()) As IQueryable(Of E)
Dim result As IQueryable(Of E) = Nothing
If includeExpressions.Any() Then
result = includeExpressions.Aggregate(Of Expression(Of Func(Of E, Object)), IQueryable(Of E))(Context.[Set](Of E)(), Function(current, expression) current.Include(expression))
End If
Return result
End Function
I believe the culprit is the following:
Function(current, expression) current.Include(expression)
I don't think the code converter (and me when I tried manually) are properly formatting this lambda expression.
Here is a link to a blog post that describes the method and purpose for using in case you would like more detail: http://www.viamacchina.com/2014/01/generic-repositories-including-includes.html
The function will not compile in VB.Net. I get an error that the includeExpressions.Aggregate call does not have the correct number of parameters. I believe this is due to the second argument not (the lambda) not properly compiling and returning its result.