Skip to content

Commit f87be69

Browse files
committed
fix model building
1 parent d0575d9 commit f87be69

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi
176176
{
177177
Type typeCast = TypeHelper.AsType(bindingInfo);
178178
PropertyInfo propertyInfo = bindingInfo as PropertyInfo;
179+
MethodInfo methodInfo = bindingInfo as MethodInfo;
179180

180181
if (typeCast != null)
181182
{
@@ -187,6 +188,11 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi
187188
PropertyDescriptor propDescr = new PropertyDescriptor(propertyInfo);
188189
bindings.Add(edmMap.EdmProperties[propDescr].Name);
189190
}
191+
else if (methodInfo != null)
192+
{
193+
PropertyDescriptor propDescr = new PropertyDescriptor(methodInfo);
194+
bindings.Add(edmMap.EdmProperties[propDescr].Name);
195+
}
190196
}
191197

192198
return String.Join("/", bindings);

src/Microsoft.AspNet.OData.Shared/Builder/NavigationSourceConfiguration.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Diagnostics.Contracts;
88
using System.Linq;
99
using System.Reflection;
10+
using System.Runtime.CompilerServices;
1011
using Microsoft.AspNet.OData.Common;
1112

1213
namespace Microsoft.AspNet.OData.Builder
@@ -525,8 +526,8 @@ private void VerifyBindingPath(NavigationPropertyConfiguration navigationConfigu
525526
Contract.Assert(navigationConfiguration != null);
526527
Contract.Assert(bindingPath != null);
527528

528-
PropertyInfo navigation = bindingPath.Last() as PropertyInfo;
529-
if (navigation == null || navigation != navigationConfiguration.PropertyInfo)
529+
MemberInfo navigation = bindingPath.Last() as MemberInfo;
530+
if (navigation == null || navigation != navigationConfiguration.PropertyInfo.MemberInfo)
530531
{
531532
throw Error.Argument("navigationConfiguration", SRResources.NavigationPropertyBindingPathIsNotValid,
532533
bindingPath.ConvertBindingPath(), navigationConfiguration.Name);
@@ -552,13 +553,25 @@ private static Type VerifyBindingSegment(Type current, MemberInfo info)
552553
return derivedType.BaseType;
553554
}
554555

556+
Type declaringType = null;
557+
Type propertyType = null;
555558
PropertyInfo propertyInfo = info as PropertyInfo;
556-
if (propertyInfo == null)
559+
MethodInfo methodInfo = info as MethodInfo;
560+
if(propertyInfo!=null)
561+
{
562+
declaringType = info.DeclaringType;
563+
propertyType = propertyInfo.PropertyType;
564+
}
565+
else if(methodInfo!=null && methodInfo.GetCustomAttribute<ExtensionAttribute>()!=null)
566+
{
567+
declaringType = methodInfo.GetParameters().First().ParameterType;
568+
propertyType = methodInfo.ReturnType;
569+
}
570+
else
557571
{
558572
throw Error.NotSupported(SRResources.NavigationPropertyBindingPathNotSupported, info.Name, info.MemberType);
559573
}
560574

561-
Type declaringType = propertyInfo.DeclaringType;
562575
if (declaringType == null ||
563576
!(declaringType.IsAssignableFrom(current) || current.IsAssignableFrom(declaringType)))
564577
{
@@ -567,12 +580,12 @@ private static Type VerifyBindingSegment(Type current, MemberInfo info)
567580
}
568581

569582
Type elementType;
570-
if (TypeHelper.IsCollection(propertyInfo.PropertyType, out elementType))
583+
if (TypeHelper.IsCollection(propertyType, out elementType))
571584
{
572585
return elementType;
573586
}
574587

575-
return propertyInfo.PropertyType;
588+
return propertyType;
576589
}
577590
}
578591
}

0 commit comments

Comments
 (0)