У меня есть Entity Framework модельUpdate Entity Framework свойство, когда другая собственность в модели изменяется
public partial class Product
{
public Product()
{
this.Designs = new HashSet<Design>();
}
public int BookingProductId { get; set; }
public System.Guid BookingId { get; set; }
public decimal Price { get; set; }
public virtual Booking Booking { get; set; }
public virtual ICollection<Design> Designs { get; set; }
}
... в котором я хотел бы обновить свойство Цены в ответ на новый дизайн добавляется к Продукт. Я пытался следовать этому примеру:
How can I change an Entity Framework ICollection to be an ObservableCollection?
поэтому мой класс выглядит следующим образом:
public partial class Product : INotifyPropertyChanged
{
public Product()
{
this.Designs = new ObservableCollection<Design>();
}
public int BookingProductId { get; set; }
public System.Guid BookingId { get; set; }
public decimal Price { get; set; }
public virtual Booking Booking { get; set; }
public virtual ObservableCollection<Design> Designs { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
, но если добавить новый дизайн продукта, как так
product.Designs.Add(new Design());
, то метод NotifyPropertyChanged никогда не запускается. Кто-нибудь знает, почему ???
Заранее спасибо
Основываясь на некоторых ответах на другие вопросы, я думаю, вы должны смотреть на 'INotifyCollectionChanged' события. –