I'm using Entity Framework Code First v 4.3.0
I have a two entities with a one to many relationship
e.g.
public class User
{
[Key]
public virtual string Username { get; set; }
public virtual ICollection<Vacation> Vacations { get; set; }
}
public class Vacation
{
public int Id { get; set; }
public virtual User User { get; set; }
public virtual string UserUsername { get; set; }
}
So the scenario is a User is created with a username of "User1". Subsequently a Vacation is created with the UserUsername field set to "User1". So we have our relationship.
If I then query the database after the Vacation is saved for the new Vacation User is null.
If I dispose of the DbContext and new it up. Requery for the Vacation User is set.
Any ideas why this might be?
Userproperty inVacationentity with[ForeignKey("UserUsername")]?