Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForeignKey properrty nullable=false not set #690

Closed
xuzhg opened this issue Mar 25, 2016 · 2 comments
Closed

ForeignKey properrty nullable=false not set #690

xuzhg opened this issue Mar 25, 2016 · 2 comments

Comments

@xuzhg
Copy link
Member

xuzhg commented Mar 25, 2016

Transferred from: OData/odata.net#337

@pysco68
Copy link

pysco68 commented Mar 25, 2016

(just subscribing notifications as I was the one opening OData/odata.net#337)

@xuzhg xuzhg changed the title ForeignKey properrty nullable=false not set ForeignKey properrty nullable=false not set Mar 28, 2016
@xuzhg
Copy link
Member Author

xuzhg commented Apr 8, 2016

@pysco68

I don't think it's a bug. The nullable of foreign key is along with the nullable of its corresponding navigation property.

So, If you mark the navigation property with [Required] attribute as follows:

public class Entity2
{
    public int Id { get; set; } 

    [Required]
    [ForeignKey("EntityOneId")]
    public virtual Entity1 EntityOne { get; set; }
    public int EntityOneId { get; set; }
}

you will get the following metadata:

image

Thanks.

@xuzhg xuzhg closed this as completed Apr 8, 2016
@xuzhg xuzhg removed the 1 - Backlog label Apr 8, 2016
0xced added a commit to 0xced/EntityFramework-Reverse-POCO-Code-First-Generator that referenced this issue Jan 29, 2019
…otationsWithFluent is true

Some context: the [Required] attribute must be set on foreign keys in order for OData.NET to properly generate its metadata document with nullable=false, see OData/WebApi#690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants