我有一個實體框架模型更新實體框架時,在模型的不同屬性更改屬性
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'事件。 –