WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Support recursive nullable complex types

Open Casimodo72 opened this issue 11 years ago • 4 comments

Hi,

I'm getting the following exception when trying to build a recursive complex type with the ODataConventionModelBuilder.

"The complex type 'DataAttachment' has a reference to itself through the property 'Items'. A recursive loop of complex types is not allowed. Parametername: propertyInfo"

According to this post the issue may already be known (https://groups.google.com/forum/#!topic/odata-discussion/zGP2wDYUmaE). Support for recursive complex types would be really great, as I'm trying to implement a flexible multipurpose container for binary attachments.

Scenario:


builder.ComplexType<DataAttachment>();

public sealed partial class DataAttachment
{
    public DataAttachment()
    {
        Header = new Dictionary<string, string>();
        Properties = new Dictionary<string, object>();
        Items = new Collection<DataAttachment>();
        BinaryData = new byte[0];
    }
    public Dictionary<string, string> Header { get; set; }
    public Dictionary<string, object> Properties { get; set; }
    public Collection<DataAttachment> Items { get; set; }
    public string Data { get; set; }
    public byte[] BinaryData { get; set; }
}

Stack trace: bei System.Web.OData.Builder.StructuralTypeConfiguration.AddCollectionProperty(PropertyInfo propertyInfo) bei System.Web.OData.Builder.ODataConventionModelBuilder.MapStructuralProperty(StructuralTypeConfiguration type, PropertyInfo property, PropertyKind propertyKind, Boolean isCollection) bei System.Web.OData.Builder.ODataConventionModelBuilder.MapComplexType(ComplexTypeConfiguration complexType) bei System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration edmType) bei System.Web.OData.Builder.ODataConventionModelBuilder.MapTypes() bei System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel() bei Ga.Web.Init.ODataConfig.Configure(HttpConfiguration config) in C:\Dev\Projects\XYZ\Ga\src\Ga.Web\AppStartup\ODataConfig.cs

I'm using: Microsoft.AspNet.OData 5.7.0-beta-150716-Nightly (and the latest nightly ODataLib packages) .NET 4.5.2 VS 2015 RC

Regards, Kasimier Buchcik

Casimodo72 avatar Jul 17 '15 16:07 Casimodo72

Complex type value is auto expanded by default.

congysu avatar Aug 07 '15 03:08 congysu

@robward-ms This issue seems to be a duplicate of https://github.com/OData/WebApi/issues/930 Also, both issues have PRs that were closed, but it isn't clear why. Any plans to follow up on this? This issue is a blocker for Complex Types support in Azure Search.

bitsforthought avatar Oct 09 '17 23:10 bitsforthought

Looks like this was fixed in #977 and is available in WebApi 6.1. I verified the fix using the test case above.

robward-ms avatar Oct 24 '17 20:10 robward-ms

This was not completely fixed. See this issue for broader context: https://github.com/OData/WebApi/issues/1248

bitsforthought avatar Jun 03 '18 22:06 bitsforthought