Why not preserve the property?

Write authorization to the chat using the Entity Framework. All in General, that was written long ago, but when I started to closely test found a bug. The user entity looks like this:
public class UserInfo
{
 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public long Id { get; set; }

 [Required, MinLength(4), MaxLength(32)]
 public string Username { get; set; }

 [Required, MinLength(4), MaxLength(32)]
 public string Password { get; set; }

 public long? RoleId { get; set; }

[ForeignKey(nameof(RoleId))]
 public RoleInfo Role { get; set; }

 public long? BanId { get; set; }

[ForeignKey(nameof(BanId))]
 public BanInfo Ban { get; set; }
}

So when registration is UserInfo and RoleInfo, Role assigned, the entity is added to the list of context and calls SaveChanges. But the authorization then only works until you stop the server. If the server is restarted (and thus the loading of the database) the entity lost the Role. Although there in the debugger it is seen that the specified RoleId, but the Role entity remains null. Why is this happening? ForeignKey is specified...

At the request of the workers... the Whole code:
public class DbContainer : DbContext
{
 public DbContainer() : base($"name={nameof(DbContainer)}") { }

 public virtual DbSet<userinfo> Users { get; set; }
 public virtual DbSet<roleinfo> Roles { get; set; }
 public virtual DbSet<baninfo> Bans { get; set; }
}

public class UserInfo
{
 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public long Id { get; set; }

 [Required, MinLength(4), MaxLength(32)]
 public string Username { get; set; }

 [Required, MinLength(4), MaxLength(32)]
 public string Password { get; set; }

 public long? RoleId { get; set; }

[ForeignKey(nameof(RoleId))]
 public RoleInfo Role { get; set; }

 public long? BanId { get; set; }

[ForeignKey(nameof(BanId))]
 public BanInfo Ban { get; set; }
}

public class BanInfo
{
 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public long Id { get; set; }

[Required]
 EndOfBan public DateTime { get; set; }

[MaxLength(64)]
 public string Reason { get; set; }
}

[Flags]
public enum UserRole : byte
{
 User = 1,
 Admin = 2,
 SuperAdmin = 4
};

public class RoleInfo
{
 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public long Id { get; set; }

[Required]
 public RoleValue UserRole { get; set; } = UserRole.User;
}</baninfo></roleinfo></userinfo>
July 9th 19 at 13:04

Find more questions by tags C#DatabasesEntity Framework