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

Fix bug that dynamic property of a (possibly collection-valued) complex type specified in model is annotated with association & navigation links #628

Closed
Lingxi-Li opened this Issue Jul 6, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@Lingxi-Li
Contributor

Lingxi-Li commented Jul 6, 2016

The following code produces this bug:

// setup model
var model = new EdmModel();
var complexType = new EdmComplexType("NS", "ComplexType");
complexType.AddStructuralProperty("PrimitiveProperty1", EdmPrimitiveTypeKind.Int64);
complexType.AddStructuralProperty("PrimitiveProperty2", EdmPrimitiveTypeKind.Int64);
var entityType = new EdmEntityType("NS", "EntityType", null, false, true);
entityType.AddKeys(
    entityType.AddStructuralProperty("PrimitiveProperty", EdmPrimitiveTypeKind.Int64));
var container = new EdmEntityContainer("NS", "Container");
var entitySet = container.AddEntitySet("EntitySet", entityType);
model.AddElements(new IEdmSchemaElement[] { complexType, entityType, container });

// setup writer
var stream = new MemoryStream();
var message = new InMemoryMessage { Stream = stream };
message.SetHeader("Content-Type", "application/json;odata.metadata=full");
var settings = new ODataMessageWriterSettings
{
    ODataUri = new ODataUri
    {
        ServiceRoot = new Uri("http://svc/")
    },
    AutoComputePayloadMetadata = true
};
var writer = new ODataMessageWriter((IODataResponseMessage)message, settings, model);

// write payload
var entitySetWriter = writer.CreateODataResourceSetWriter(entitySet);
entitySetWriter.WriteStart(new ODataResourceSet());
entitySetWriter.WriteStart(
    new ODataResource
    {
        Properties = new[]
        {
            new ODataProperty { Name = "PrimitiveProperty", Value = 1L }
        }
    }
);
entitySetWriter.WriteStart(
    new ODataNestedResourceInfo
    {
        Name = "DynamicComplexProperty",
        IsUndeclared = true
    }
);
entitySetWriter.WriteStart(
    new ODataResource
    {
        TypeName = "NS.ComplexType",
        Properties = new[]
        {
            new ODataProperty { Name = "PrimitiveProperty1", Value = 1L },
            new ODataProperty { Name = "PrimitiveProperty2", Value = 2L }
        }
    }
);
entitySetWriter.WriteEnd();
entitySetWriter.WriteEnd();
entitySetWriter.WriteEnd();
entitySetWriter.WriteEnd();
var str = Encoding.UTF8.GetString(stream.ToArray());

The code produces the payload:

{
  "@odata.context": "http://svc/$metadata#EntitySet",
  "value": [
    {
      "@odata.id": "EntitySet(1)",
      "@odata.editLink": "EntitySet(1)",
      "PrimitiveProperty@odata.type": "#Int64",
      "PrimitiveProperty": 1,
      "DynamicComplexProperty@odata.associationLink": "http://svc/EntitySet(1)/DynamicComplexProperty/$ref",
      "DynamicComplexProperty@odata.navigationLink": "http://svc/EntitySet(1)/DynamicComplexProperty",
      "DynamicComplexProperty": {
        "@odata.type": "#NS.ComplexType",
        "PrimitiveProperty1@odata.type": "#Int64",
        "PrimitiveProperty1": 1,
        "PrimitiveProperty2@odata.type": "#Int64",
        "PrimitiveProperty2": 2
      }
    }
  ]
}

Note that DynamicComplexProperty is annotated with odata.associationLink and odata.navigationLink despite the fact that it's of a complex type NS.ComplexType defined in the data model.

@Lingxi-Li Lingxi-Li added the bug label Jul 6, 2016

@Lingxi-Li Lingxi-Li self-assigned this Jul 6, 2016

@Lingxi-Li Lingxi-Li changed the title from Dynamic property of a complex type specified in model is annotated with association and navigation links to Fix bug that dynamic property of a complex type specified in model is annotated with association & navigation links Jul 6, 2016

@Lingxi-Li Lingxi-Li added in-progress bugfix and removed bug labels Jul 6, 2016

Lingxi-Li added a commit that referenced this issue Jul 7, 2016

Fix bug that dynamic complex property be treated as nav. property #628
Fix bug that dynamic property of a complex type specified in model is annotated with association & navigation links.

@Lingxi-Li Lingxi-Li closed this Jul 7, 2016

@LaylaLiu LaylaLiu removed the in-progress label Jul 7, 2016

@Lingxi-Li

This comment has been minimized.

Contributor

Lingxi-Li commented Jul 7, 2016

The problem still persists for dynamic collection-valued complex property.

@Lingxi-Li Lingxi-Li reopened this Jul 7, 2016

@Lingxi-Li Lingxi-Li changed the title from Fix bug that dynamic property of a complex type specified in model is annotated with association & navigation links to Fix bug that dynamic property of a (possibly collection-valued) complex type specified in model is annotated with association & navigation links Jul 7, 2016

Lingxi-Li added a commit that referenced this issue Jul 8, 2016

Fix bug that dynamic collection-valued complex property is treated as…
… nav. property #628

Fix bug that dynamic collection-valued property of a complex type specified in model is annotated with association & navigation links.

@Lingxi-Li Lingxi-Li closed this Jul 8, 2016

@LaylaLiu LaylaLiu removed the in-progress label Jul 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment