OData / ODataConnectedService

A Visual Studio extension for generating client code for OData Services
Other
79 stars 41 forks source link

Do not annotate property required on generated model when that property isn't defined Required into EdmModel #366

Closed rpallares closed 1 year ago

rpallares commented 1 year ago

Describe the bug

Some properties defined as optional into the base model: c#public IList<int>? SomeList { get; set; }

Are translated to a Required property when ODataConnectedServices generate the client.

[global::Microsoft.OData.Client.OriginalNameAttribute("SomeList")]
[global::System.ComponentModel.DataAnnotations.RequiredAttribute(ErrorMessage = "SomeList is required.")]
public virtual global::System.Collections.ObjectModel.ObservableCollection<int> SomeList
{
    get
    {
        return this._SomeList;
    }
    set
    {
        this.OnSomeListChanging(value);
        this._SomeList = value;
        this.OnSomeListChanged();
        this.OnPropertyChanged("SomeList");
    }
}

Version of the Project affected

ODataConnectedService v1.0.0 VisualStudio Version v17.6.4 Microsoft.Odata.Client v7.17.0

To Reproduce

Steps to reproduce the behavior:

  1. Create a simple entity which have an optional list declared
  2. Declare the EdmModel using ODataConventionalModelBuilder
  3. Generate the client using latest ODataConnectedServices

Expected behavior

The generated model must have the same Required restrictions than the original model

Actual behavior

IList? properties without any Required attribute must not become Required at client side

Screenshots

NA

Additional context

NA

rpallares commented 1 year ago

Finally the issue looks more at ODataConventionalModelBuilder side as they don't generate the right model for IList. But it's doing it correctly for IList