I have this generated entity:
public partial class Player
{
public int Id { get; set; }
public string Name { get; set; }
public System.DateTime Birthdate { get; set; }
public PlayerPosition Position { get; set; }
public int IdTeam { get; set; }
public virtual Team Team { get; set; }
}
I want to make a method to update the position of a player.
I am doing this:
Player playerToUpdate = new Player
{
Id = 34,
Position=PlayerPosition.Defender
};
playersRepository.Attach(playerToUpdate);
playersRepository.UpdatePosition(playerToUpdate);
public void Attach(T entity)
{
DbSet.Attach(entity);
}
public void UpdatePosition(Player playerToUpdate)
{
Context.Entry(playerToUpdate).Property(p => p.Position).IsModified = true;
}
I get a validation exception (The name field is required)
What is the way to fix it?
Thanks.