私はこの生成されたエンティティを持っています:
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; }
}
選手の位置を更新するメソッドを作りたいです。
私はこれをやっています:
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;
}
検証例外が発生します (名前フィールドは必須です)
それを修正する方法は何ですか?
ありがとう。