我正在使用vb.net 2013.
我尝试使用我使用NUGET安装的工具.
EntityFramewrok.Utilities / link: https://github.com/MikaelEliasson/EntityFramework.Utilities
这是一个开源的DLL,可以下载整个代码.
从这个DLL,我正在尝试使用“IncludeEFU”方法.
在上面的链接中,是我在C#项目上使用的代码并且有效:
我尝试使用我使用NUGET安装的工具.
EntityFramewrok.Utilities / link: https://github.com/MikaelEliasson/EntityFramework.Utilities
这是一个开源的DLL,可以下载整个代码.
从这个DLL,我正在尝试使用“IncludeEFU”方法.
在上面的链接中,是我在C#项目上使用的代码并且有效:
- var result = db.Contacts
- .IncludeEFU(db,x => x.PhoneNumbers
- .Where(n => n.Number == "10134")
- .OrderBy(p => p.ContactId)
- .ThenByDescending(p => p.Number))
- .ToList();
我尝试在我的VB.net应用程序上使用相同的代码:
- 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()
但我收到一个错误:
- An unhandled exception of type 'System.ArgumentException' occurred in EntityFramework.Utilities.dll
- Additional information: Could not find a MemberExpression
逐个检查dll项目中的文件(可以在链接上下载),我看到我收到的错误消息来自这个子:
- 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;
- }
看看这一行:
- throw new ArgumentException("Could not find a MemberExpression","collectionSelector");
为什么这是在C#项目上工作,并在VB.net项目上产生这个错误?
我该如何解决这个问题?
谢谢 !
编辑:我尝试在该子目录中进行一些更改:
- ...
- 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;
- }
- .....