OData / OData/AspNetCoreOData

Missing Nullable="false" if navigation property

Open
#592 7 comments 0 reactions 1 assignee View on GitHub

@chrisspre is already working on this.

Since May 10, 2022.

enhancement followup P3
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
ASP.NET Core OData 8.x

Describe the bug
Nullable="false" is missing on the property if a navigation property is present.

Reproduce steps
2 simples class, generating project, see $metadata

Data Model

public class Author
{
    public int AuthorId { get; set; }
    public string AuthorName { get; set; }
}
public class Book
{
    public int BookId { get; set; }
    public string BookTitle { get; set; }
    public int AuthorId { get; set; }

    public virtual Author Author { get; set; }
}

EDM Builder

var edmBuilder = new ODataConventionModelBuilder();
edmBuilder.EntitySet<Author>("Author");
edmBuilder.EntitySet<Book>("Book");

EDM (CSDL) Model

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
  <edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EntityType Name="Author">
        <Key>
          <PropertyRef Name="AuthorId"/>
        </Key>
        <Property Name="AuthorId" Type="Edm.Int32" Nullable="false"/>
        <Property Name="AuthorName" Type="Edm.String"/>
      </EntityType>
      <EntityType Name="Book">
        <Key>
          <PropertyRef Name="BookId"/>
        </Key>
        <Property Name="BookId" Type="Edm.Int32" Nullable="false"/>
        <Property Name="BookTitle" Type="Edm.String"/>
        <Property Name="AuthorId" Type="Edm.Int32"/>
        <NavigationProperty Name="Author" Type="Author">
          <ReferentialConstraint Property="AuthorId" ReferencedProperty="AuthorId"/>
        </NavigationProperty>
      </EntityType>
    </Schema>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
      <EntityContainer Name="Container">
        <EntitySet Name="Author" EntityType="Author"/>
        <EntitySet Name="Book" EntityType="Book">
          <NavigationPropertyBinding Path="Author" Target="Author"/>
        </EntitySet>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

Expected behavior

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
  <edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EntityType Name="Author">
        <Key>
          <PropertyRef Name="AuthorId"/>
        </Key>
        <Property Name="AuthorId" Type="Edm.Int32" Nullable="false"/>
        <Property Name="AuthorName" Type="Edm.String"/>
      </EntityType>
      <EntityType Name="Book">
        <Key>
          <PropertyRef Name="BookId"/>
        </Key>
        <Property Name="BookId" Type="Edm.Int32" Nullable="false"/>
        <Property Name="BookTitle" Type="Edm.String"/>
        <Property Name="AuthorId" Type="Edm.Int32" Nullable="false"/>
        <NavigationProperty Name="Author" Type="Author" Nullable="false">
          <ReferentialConstraint Property="AuthorId" ReferencedProperty="AuthorId"/>
        </NavigationProperty>
      </EntityType>
    </Schema>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
      <EntityContainer Name="Container">
        <EntitySet Name="Author" EntityType="Author"/>
        <EntitySet Name="Book" EntityType="Book">
          <NavigationPropertyBinding Path="Author" Target="Author"/>
        </EntitySet>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

<Property Name="AuthorId" Type="Edm.Int32" Nullable="false"/>
<NavigationProperty Name="Author" Type="Author" Nullable="false">

If I comment the navigation property, I get the good return :
<Property Name="AuthorId" Type="Edm.Int32" Nullable="false"/>

Contributor guide

No contributing guide indexed for this repository

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.