Skip to content

Support extension method as Navigation property #1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODa
{
if (!property.AddedExplicitly)
{
edmTypeConfiguration.RemoveProperty(property.PropertyInfo);
edmTypeConfiguration.RemoveProperty(property.PropertyInfo.PropertyInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ private static void ApplyNavigation(NavigationPropertyConfiguration navProperty,
{
Type dependentType = Nullable.GetUnderlyingType(dependent.PropertyInfo.PropertyType) ?? dependent.PropertyInfo.PropertyType;
PrimitivePropertyConfiguration principal = principalEntity.Keys.FirstOrDefault(
k => k.PropertyInfo.PropertyType == dependentType && navProperty.PrincipalProperties.All(p => p != k.PropertyInfo));
k => k.PropertyInfo.PropertyType == dependentType && navProperty.PrincipalProperties.All(p => p != k.PropertyInfo.MemberInfo));

if (principal != null)
{
@@ -136,7 +136,7 @@ private static void ApplyPrimitive(PrimitivePropertyConfiguration dependent, Ent

Type dependentType = Nullable.GetUnderlyingType(dependent.PropertyInfo.PropertyType) ?? dependent.PropertyInfo.PropertyType;
PrimitivePropertyConfiguration principal = principalEntity.Keys.FirstOrDefault(
k => k.PropertyInfo.PropertyType == dependentType && navProperty.PrincipalProperties.All(p => p != k.PropertyInfo));
k => k.PropertyInfo.PropertyType == dependentType && navProperty.PrincipalProperties.All(p => p != k.PropertyInfo.MemberInfo));
if (principal != null)
{
navProperty.HasConstraint(dependent.PropertyInfo, principal.PropertyInfo);
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public override void Apply(PropertyConfiguration edmProperty,
}
else
{
structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo);
structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo.PropertyInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ public override void Apply(StructuralPropertyConfiguration edmProperty,
EntityTypeConfiguration entity = structuralTypeConfiguration as EntityTypeConfiguration;
if (entity != null)
{
entity.HasKey(edmProperty.PropertyInfo);
entity.HasKey(edmProperty.PropertyInfo.PropertyInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public override void Apply(PropertyConfiguration edmProperty,

if (!edmProperty.AddedExplicitly)
{
structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo);
structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo.PropertyInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public override void Apply(EntityTypeConfiguration entity, ODataConventionModelB
PropertyConfiguration key = GetKeyProperty(entity);
if (key != null)
{
entity.HasKey(key.PropertyInfo);
entity.HasKey(key.PropertyInfo.PropertyInfo);
}
}

19 changes: 13 additions & 6 deletions src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs
Original file line number Diff line number Diff line change
@@ -176,6 +176,7 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi
{
Type typeCast = TypeHelper.AsType(bindingInfo);
PropertyInfo propertyInfo = bindingInfo as PropertyInfo;
MethodInfo methodInfo = bindingInfo as MethodInfo;

if (typeCast != null)
{
@@ -184,7 +185,13 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi
}
else if (propertyInfo != null)
{
bindings.Add(edmMap.EdmProperties[propertyInfo].Name);
MemberDescriptor propDescr = new MemberDescriptor(propertyInfo);
bindings.Add(edmMap.EdmProperties[propDescr].Name);
}
else if (methodInfo != null)
{
MemberDescriptor propDescr = new MemberDescriptor(methodInfo);
bindings.Add(edmMap.EdmProperties[propDescr].Name);
}
}

@@ -438,7 +445,7 @@ private static Dictionary<Type, IEdmType> AddTypes(this EdmModel model, EdmTypeM
model.AddClrTypeAnnotations(edmTypes);

// add annotation for properties
Dictionary<PropertyInfo, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
Dictionary<MemberDescriptor, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
model.AddClrPropertyInfoAnnotations(edmProperties);
model.AddClrEnumMemberInfoAnnotations(edmTypeMap);
model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions);
@@ -503,13 +510,13 @@ private static void AddClrTypeAnnotations(this EdmModel model, Dictionary<Type,
}
}

private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<PropertyInfo, IEdmProperty> edmProperties)
private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<MemberDescriptor, IEdmProperty> edmProperties)
{
foreach (KeyValuePair<PropertyInfo, IEdmProperty> edmPropertyMap in edmProperties)
foreach (KeyValuePair<MemberDescriptor, IEdmProperty> edmPropertyMap in edmProperties)
{
IEdmProperty edmProperty = edmPropertyMap.Value;
PropertyInfo clrProperty = edmPropertyMap.Key;
if (edmProperty.Name != clrProperty.Name)
MemberDescriptor clrProperty = edmPropertyMap.Key;
if (clrProperty.MethodInfo != null || edmProperty.Name != clrProperty.Name)
{
model.SetAnnotationValue(edmProperty, new ClrPropertyInfoAnnotation(clrProperty));
}
8 changes: 5 additions & 3 deletions src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ internal class EdmTypeBuilder
{
private readonly List<IEdmTypeConfiguration> _configurations;
private readonly Dictionary<Type, IEdmType> _types = new Dictionary<Type, IEdmType>();
private readonly Dictionary<PropertyInfo, IEdmProperty> _properties = new Dictionary<PropertyInfo, IEdmProperty>();
private readonly Dictionary<MemberDescriptor, IEdmProperty> _properties = new Dictionary<MemberDescriptor, IEdmProperty>();
private readonly Dictionary<IEdmProperty, QueryableRestrictions> _propertiesRestrictions = new Dictionary<IEdmProperty, QueryableRestrictions>();
private readonly Dictionary<IEdmProperty, ModelBoundQuerySettings> _propertiesQuerySettings = new Dictionary<IEdmProperty, ModelBoundQuerySettings>();
private readonly Dictionary<IEdmStructuredType, ModelBoundQuerySettings> _structuredTypeQuerySettings = new Dictionary<IEdmStructuredType, ModelBoundQuerySettings>();
@@ -462,7 +462,8 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
foreach (PropertyInfo propInfo in propertyInfos)
{
IEdmProperty edmProperty;
if (_properties.TryGetValue(propInfo, out edmProperty))
MemberDescriptor propDescr = new MemberDescriptor(propInfo);
if (_properties.TryGetValue(propDescr, out edmProperty))
{
edmProperties.Add(edmProperty);
}
@@ -473,7 +474,8 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
while (baseType != null)
{
PropertyInfo basePropInfo = baseType.GetProperty(propInfo.Name);
if (_properties.TryGetValue(basePropInfo, out edmProperty))
MemberDescriptor basePropDescr = new MemberDescriptor(basePropInfo);
if (_properties.TryGetValue(basePropDescr, out edmProperty))
{
edmProperties.Add(edmProperty);
break;
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeMap.cs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ internal class EdmTypeMap
{
public EdmTypeMap(
Dictionary<Type, IEdmType> edmTypes,
Dictionary<PropertyInfo, IEdmProperty> edmProperties,
Dictionary<MemberDescriptor, IEdmProperty> edmProperties,
Dictionary<IEdmProperty, QueryableRestrictions> edmPropertiesRestrictions,
Dictionary<IEdmProperty, ModelBoundQuerySettings> edmPropertiesQuerySettings,
Dictionary<IEdmStructuredType, ModelBoundQuerySettings> edmStructuredTypeQuerySettings,
@@ -31,7 +31,7 @@ public EdmTypeMap(

public Dictionary<Type, IEdmType> EdmTypes { get; private set; }

public Dictionary<PropertyInfo, IEdmProperty> EdmProperties { get; private set; }
public Dictionary<MemberDescriptor, IEdmProperty> EdmProperties { get; private set; }

public Dictionary<IEdmProperty, QueryableRestrictions> EdmPropertiesRestrictions { get; private set; }

Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ public EntityTypeConfiguration<TEntityType> DerivesFrom<TBaseType>() where TBase
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Explicit Expression generic type is more clear")]
public EntityTypeConfiguration<TEntityType> HasKey<TKey>(Expression<Func<TEntityType, TKey>> keyDefinitionExpression)
{
ICollection<PropertyInfo> properties = PropertySelectorVisitor.GetSelectedProperties(keyDefinitionExpression);
ICollection<MemberInfo> properties = PropertySelectorVisitor.GetSelectedProperties(keyDefinitionExpression, false);
foreach (PropertyInfo property in properties)
{
_configuration.HasKey(property);
Loading