OData / ODataConnectedService

A Visual Studio extension for generating client code for OData Services
Other
81 stars 44 forks source link

DynamicProperties property for open type entity not wrapped with ContainerProperty attribute #380

Closed stanb closed 7 months ago

stanb commented 8 months ago

Describe the bug

I have service with open type entity:

    public class ResultObject
    {
        public string Id { get; set; } = string.Empty;
        public IDictionary<string, object> DynamicProperties { get; set; } = new Dictionary<string, object>();
    }

Metadata:

      <EntityType Name="ResultObject" OpenType="true">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Edm.String" Nullable="false" />
      </EntityType>

ODataConnectedService generated class:

    [global::Microsoft.OData.Client.Key("Id")]
    [global::Microsoft.OData.Client.OriginalNameAttribute("ResultObject")]
    public partial class ResultObject : global::Microsoft.OData.Client.BaseEntityType
    {
        /// <summary>
        /// Create a new ResultObject object.
        /// </summary>
        /// <param name="ID">Initial value of Id.</param>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
        public static ResultObject CreateResultObject(string ID)
        {
            ResultObject resultObject = new ResultObject();
            resultObject.Id = ID;
            return resultObject;
        }
        /// <summary>
        /// There are no comments for Property Id in the schema.
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]

        [global::Microsoft.OData.Client.OriginalNameAttribute("Id")]
        [global::System.ComponentModel.DataAnnotations.RequiredAttribute(ErrorMessage = "Id is required.")]
        public virtual string Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                this.OnIdChanging(value);
                this._Id = value;
                this.OnIdChanged();
            }
        }
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
        private string _Id;
        partial void OnIdChanging(string value);
        partial void OnIdChanged();
        /// <summary>
        /// There are no comments for Property DynamicProperties in the schema.
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]

        [global::Microsoft.OData.Client.OriginalNameAttribute("DynamicProperties")]
        public virtual global::System.Collections.Generic.IDictionary<string, object> DynamicProperties
        {
            get
            {
                return this._DynamicProperties;
            }
            set
            {
                this.OnDynamicPropertiesChanging(value);
                this._DynamicProperties = value;
                this.OnDynamicPropertiesChanged();
            }
        }
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
        private global::System.Collections.Generic.IDictionary<string, object> _DynamicProperties = new global::System.Collections.Generic.Dictionary<string, object>();
        partial void OnDynamicPropertiesChanging(global::System.Collections.Generic.IDictionary<string, object> value);
        partial void OnDynamicPropertiesChanged();
    }

DynamicProperties property on generated class missing [ContainerProperty] attribute.

Version of the Project affected

ODataConnectedService v1.0.2.0 VisualStudio Version v17.8.7 Microsoft.Odata.Client v7.20.0

To Reproduce

Create or update connected service

Expected behavior

DynamicProperties property should have [ContainerPropertyAttribute] attribute

Actual behavior

DynamicProperties property does not have [ContainerPropertyAttribute] attribute

stanb commented 8 months ago

https://github.com/OData/ODataConnectedService/blob/46241bba715de691ed0b9c872ab0cdcb56577d9a/src/ODataConnectedService.Shared/ConnectedServiceFileHandler.cs#L74-L93

Any idea why it bound to specific version of Microsoft.OData.Client? ODataCliFileHandler.EmitContainerPropertyAttribute() returns true unconditionally. https://github.com/OData/ODataConnectedService/blob/46241bba715de691ed0b9c872ab0cdcb56577d9a/src/Microsoft.OData.Cli/ODataCliFileHandler.cs#L93-L96

gathogojr commented 7 months ago

Fixed by https://github.com/OData/ODataConnectedService/pull/381

stanb commented 7 months ago

Do you have a plan on releasing a new version of VS extension? We need this fix.

gathogojr commented 7 months ago

Hi @stanb. We're almost here. We are finalizing on this pull request https://github.com/OData/ODataConnectedService/pull/388, and then merge the version bump pull request https://github.com/OData/ODataConnectedService/pull/387, then do the release.