İlgili varlık koleksiyonunu yenilemede sorun yaşıyorum.Varlık Çerçevesi POCO - Bir gezinme özelliğini yenileyin
Esasen sorun şöyledir:
public class Student
{
public virtual ICollection<Lecture> Lectures { get; set; }
public void AddLecture(Lecture lecture)
{
Lectures.Add(lecture);
}
public void CancelChanges()
{
_context.Refresh(RefreshMode.StoreWins, this);
_context.LoadProperty(this, (o) => o.Lectures,
MergeOption.OverwriteChanges);
}
}
public class Grade
{
public virtual Student { get; set; }
}
Şimdi biz düzenleme işlemini iptal edebilirsiniz istiyorsam, dersler eklemek için bazı GUI ve: Yani
public void ExampleEdit()
{
Student student = _context.Students.SingleOrDefault(/* blah */);
student.AddLecture(_context.Lectures.SingleOrDefault(/* e.g. math */));
student.CancelChanges();
// At this point student SHOULD have no lectures anymore since the
// property was loaded with overwrite changes option.
// Yet the Lectures still contains the lecture we added there
}
, kodudur kötü? Yanlış kullandığım bir yöntem var mı? Tüm nesneyi TAMAMEN yeniden yüklemek mümkün mü? ..
teşekkürler açıklama için çok - bu şeylerin çok daha net bir sürü yaptı kafamın içinde. Ve önerdiğiniz çözüm çok kullanışlıdır - Kodumu yeni güncelledim ve aslında işe yarar. – Jefim
Çok hoş geldiniz, yardım ettiğine sevindim :) –