Sorry for my bad English.
I have some class and EF Context generate from DB
1.Question
public int Id { get; set; }
public string Content { get; set; }
public virtual ICollection<Answer> Answer { get; set; }
2.Answer
public int Id { get; set; }
public string Content { get; set; }
public bool IsTrue { get; set; }
public virtual Question Question { get; set; }
All CRUD made through the Service. This is Update method for Question
public void Update(Question q)
{
var editQuestion = GetById(q.Id); //get entity by id
editQuestion.Answer = null;
_repository.Update(editQuestion);
q.Answer.Each(answer => answer.Question=editQuestion);
editQuestion.Answer = q.Answer;
editQuestion.Content = q.Content;
_repository.Update(editQuestion);
_unitOfWork.Commit();
}
_repository.Update(T Entity) =>
public virtual void Update(T entity)
{
DbEntityEntry entityEntry = _context.Entry<T>(entity);
entityEntry.State = EntityState.Modified;
}
Now in Db not update old Answer, but added new (q.Answer). In q.Answer may contains updated old Answer and some new.
How I can update Question?
UPD: _unitOfWork.Commit()
public void Commit()
{
_context.SaveChanges();
}