WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

navigation property in a complex type

Open LianwMS opened this issue 11 years ago • 17 comments

Consider support navigation property (at least non-contained nav prop, since contained nav prop is not supported by ODL yet) in a complex type.

                    // navigation property in a complex type ?
                    if (mappedType == null)
                    {
                        // the user told nothing about this type and this is the first time we are seeing this type.
                        // complex types cannot contain entities. So, treat it as complex property.
                        MapStructuralProperty(complexType, property, PropertyKind.Complex, isCollection);
                    }
                    else if (_explicitlyAddedTypes.Contains(mappedType))
                    {
                        // user told us that this is an entity type.
                        throw Error.InvalidOperation(SRResources.ComplexTypeRefersToEntityType, complexType.ClrType.FullName, mappedType.ClrType.FullName, property.Name);
                    }
                    else
                    {
                        // we tried to be over-smart earlier and made the bad choice. so patch up now.
                        EntityTypeConfiguration mappedTypeAsEntity = mappedType as EntityTypeConfiguration;
                        Contract.Assert(mappedTypeAsEntity != null);

                        ReconfigureEntityTypesAsComplexType(new EntityTypeConfiguration[] { mappedTypeAsEntity });

                        MapStructuralProperty(complexType, property, PropertyKind.Complex, isCollection);
                    }

Work Item Details

Original CodePlex Issue: Issue 1765 Status: Proposed Reason Closed: Unassigned Assigned to: Unassigned Reported on: Mar 17, 2014 at 2:20 PM Reported by: cysu Updated on: Apr 17, 2014 at 10:54 AM Updated by: zjufish

LianwMS avatar Jan 12 '15 01:01 LianwMS

vote for adding this feature

daboxu avatar Jul 20 '15 17:07 daboxu

Any updates on adding this into a new release?

crgeee avatar Aug 12 '15 18:08 crgeee

+1

cohenomri avatar Sep 06 '15 13:09 cohenomri

see the initial design spec: http://odata.github.io/odata.net/#07-03-NavigationProperty-In-ComplexType

xuzhg avatar Jan 06 '16 02:01 xuzhg

+1

Casimodo72 avatar Jan 28 '16 20:01 Casimodo72

+1

rbonini-doit avatar Feb 26 '16 17:02 rbonini-doit

Definitely +1

sebekz avatar May 16 '16 11:05 sebekz

+1

zfkingth avatar Aug 12 '16 07:08 zfkingth

Absolutely + 1

Catchops avatar Nov 17 '16 15:11 Catchops

Please :) +1

SeanSafken avatar Dec 01 '16 19:12 SeanSafken

+1

MaxOverDev avatar Apr 13 '17 15:04 MaxOverDev

+1

asido avatar Apr 25 '17 17:04 asido

This is a critical feature for us. Can it be fixed ASAP?

santhudr avatar Sep 14 '17 09:09 santhudr

@santhudr @Asido @MaxOverDev @SeanSafken @Catchops @zfkingth @sebekz @rbonini @Casimodo72 ...

In Web API OData v6.0.0 release, we supports the functionality of this feature. See detail at: https://github.com/OData/WebApi/releases/tag/v6.0.0

You can try the latest package on nuget.org as: https://www.nuget.org/packages/Microsoft.AspNet.OData/6.1.0

We'd love to get any feedback from you.

Thanks!

xuzhg avatar Sep 14 '17 17:09 xuzhg

I've updated the package to 6.1.0. I'm trying to expand on the NavigationProperty of a ComplexType and I am getting this error:

{ "message": "The query specified in the URI is not valid. A path within the select or expand query option is not supported.", "innererror": { "message": "A path within the select or expand query option is not supported.", "type": "Microsoft.OData.ODataException", "stacktrace": " at System.Web.OData.Formatter.Serialization.SelectExpandNode.ValidatePathIsSupported(ODataPath path)\r\n at System.Web.OData.Query.Expressions.SelectExpandBinder.GetPropertiesToExpandInQuery(SelectExpandClause selectExpandClause)\r\n at System.Web.OData.Query.Expressions.SelectExpandBinder.ProjectElement(Expression source, SelectExpandClause selectExpandClause, IEdmEntityType entityType, IEdmNavigationSource navigationSource)\r\n at System.Web.OData.Query.Expressions.SelectExpandBinder.GetProjectionLambda()\r\n at System.Web.OData.Query.Expressions.SelectExpandBinder.Bind(Object entity)\r\n at System.Web.OData.Query.SelectExpandQueryOption.ApplyTo(Object entity, ODataQuerySettings settings)\r\n at System.Web.OData.Query.ODataQueryOptions.ApplySelectExpand[T](T entity, ODataQuerySettings querySettings)\r\n at System.Web.OData.Query.ODataQueryOptions.ApplyTo(Object entity, ODataQuerySettings querySettings)\r\n at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext)\r\n at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)" }}

The URL is: odata/v1/Reports(1)?$expand=ReportTargets/ReportTargetLookup Where ReportTarget is a ComplexType and ReportTargetLookup is a Navigational Property. Model structure is:

Class Report { ... public List<ReportTarget> ReportTargets{get;set;} ... }

Class ReportTarget { ... public ReportTargetLookup ReportTargetLookup{get;set;} ... }

Am I missing something?

santhudr avatar Sep 15 '17 12:09 santhudr

@santhudr No, you didn't.

So far, Complex type with Navigation property only supports to create the metadata, for example:

image

That's why this issue still opens.

xuzhg avatar Sep 15 '17 22:09 xuzhg

It should support after https://github.com/OData/WebApi/pull/1738. Please open new issue if you have further concerns. Thanks.

xuzhg avatar Oct 02 '19 23:10 xuzhg