I'm using Entity Framework 4.3 and doing code first. I have two tables that are in a 1 to 0 or 1 relationship like such...
class User
{
[key]
public int UserID {get; set;}
// other props
}
class UserStats
{
[key]
public int UserID {get; set;}
// other props
public virtual User User {get; set;}
}
I'm also using ASP.Net WebAPI 2.2 w/ OData v4 and the OData Client Code Generator template.
The metadata file that WebAPI creates is missing the IsNullable="False"
attribute on the User's UserID
property. So the OData Client Code Generator is making the User class's UserID
property nullable, which is not true, especially with it being the primary key.
I've tried adding [Required]
to the User
property on UserStats, however then any updates will throw a validation exception if I don't include a User
when saving/updating the UserStats
class.
I feel like I'm missing something.