Skip to content

Nullability of property when property is a collection of enum type is not correct #58

@dotnet-enthusiast

Description

@dotnet-enthusiast

Using ODataConventionModelBuilder, I generate a complex type with the following property.

public class RecurrencePattern
{
    public List<DayOfWeek>? DaysOfWeek { get; set; }
}

where DayOfWeek is defined as an enumeration.

public enum DayOfWeek
{
    Sunday = 0,
    Monday = 1,
    Tuesday = 2,
    Wednesday = 3,
    Thursday = 4,
    Friday = 5,
    Saturday = 6
}

Wrote a simple unit test to compare the IEdmModel generated from my code vs one generated from an csdl file, to ensure that my api workload doesn't introduce any breaking changes.

The IEdmModel generated from the schema has the following configuration.

<ComplexType Name="recurrencePattern">
  <Property Name="type" Type="microsoft.graph.recurrencePatternType" />
  <Property Name="interval" Type="Edm.Int32" Nullable="false" />
  <Property Name="month" Type="Edm.Int32" Nullable="false" />
  <Property Name="dayOfMonth" Type="Edm.Int32" Nullable="false" />
  <Property Name="daysOfWeek" Type="Collection(microsoft.graph.dayOfWeek)" />
  <Property Name="firstDayOfWeek" Type="microsoft.graph.dayOfWeek" />
  <Property Name="index" Type="microsoft.graph.weekIndex" />
</ComplexType>
<EnumType Name="dayOfWeek">
  <Member Name="sunday" Value="0" />
  <Member Name="monday" Value="1" />
  <Member Name="tuesday" Value="2" />
  <Member Name="wednesday" Value="3" />
  <Member Name="thursday" Value="4" />
  <Member Name="friday" Value="5" />
  <Member Name="saturday" Value="6" />
</EnumType>

When I compare the property daysOfWeek on the recurencePattern type generated from the ODataConventionModelBuilder vs the one generated from the csdl, the property has Nullable=false on the ODataConvetionModelBuilder and Nullable=true on the one generated from the csdl.

Expection:

I would expect the property to be Nullable=true when using the ODataConventionModelBuilder. I have confirmed that is the case when the collection is an entity type or complex type, but not when it is a collection of enumerations as shown above.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions