I'm using vb.net 2013. I try to use a tool that I have installed using NUGET. EntityFramewrok.Utilities / link : https://github.com/MikaelEliasson/EntityFramework.Utilities This is an open source dll and the whole code can be downloaded. From this DLL , I'm trying to use the "IncludeEFU" method. In the link above , is a code that I use on C# project and works :
var result = db.Contacts
.IncludeEFU(db, x => x.PhoneNumbers
.Where(n => n.Number == "10134")
.OrderBy(p => p.ContactId)
.ThenByDescending(p => p.Number))
.ToList();
I try to use on my VB.net application the same code like this :
Dim result = db.Contacts _
.IncludeEFU(db, Function(x) x.PhoneNumbers _
.Where(Function(n) n.Number = "10134")_
.OrderBy(Function(p) p.ContactId) _
.ThenByDescending(Function(p) p.Number)).ToList()
But I'm getting an error :
An unhandled exception of type 'System.ArgumentException' occurred in EntityFramework.Utilities.dll
Additional information: Could not find a MemberExpression
Inspecting one by one the files in the dll's project ( that can be downloaded on the link ) , I see that the error message that I'm getting come from this sub :
private static PropertyInfo SetCollectionModifiersAndGetChildProperty<T, TChild>(Expression<Func<T, IEnumerable<TChild>>> collectionSelector, List<MethodCallExpression> childCollectionModifiers)
where T : class
where TChild : class
{
var temp = collectionSelector.Body;
while (temp is MethodCallExpression)
{
var mce = temp as MethodCallExpression;
childCollectionModifiers.Add(mce);
temp = mce.Arguments[0];
}
childCollectionModifiers.Reverse(); //We parse from right to left so reverse it
if (!(temp is MemberExpression))
{
throw new ArgumentException("Could not find a MemberExpression", "collectionSelector");
}
var childProp = (temp as MemberExpression).Member as PropertyInfo;
return childProp;
}
Look at the line :
throw new ArgumentException("Could not find a MemberExpression", "collectionSelector");
Why this is working on a C# project , and produce this error on a VB.net project ? How can I resolve this problem ? Thank you !
Edited : I try to make some changes in that sub :
...
while (temp is MethodCallExpression)
{
var mce = temp as MethodCallExpression;
childCollectionModifiers.Add(mce);
temp = mce.Arguments[0];
}
while (temp is UnaryExpression)
{
var ue = temp as UnaryExpression;
temp = ue.Operand;
}
.....
After I rebuild the dll file , and now the error message is disappear. But can anyone confirm that this is a correct solution ?