I'm using EF Core to create a "MenuItem" table, which may be linked to a parent (of "MenuItem") like so ...
public class MenuItem
{
public int MenuItemId { get; set; }
[ForeignKey("ParentMenuItemId")]
public virtual MenuItem Parent { get; set; }
}
ParentMenuItemId gets created as NOT NULL - how can I define it so Parent may be null (for root level MenuItem records)?
well, it's easy. all you have to do is this putting a
?after defining type of object like this:but, you need to make sure there is a no such as
[Required]tags on that relation object.