OData / OData/ModelBuilder

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

Open
#58 2 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Nov 4, 2025.

follow-up
Dominant language
C#
Stars
22
Forks
24
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.