Bv202 Bv202 - 1 year ago 172
C# Question

Adding INotifyPropertyChange in generated EF classes

So, my classes are auto-generated by EF:

// <auto-generated>
// This code was generated from a template.
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>

namespace Testje.Models
using System;
using System.Collections.Generic;

public partial class Ploeg
public Ploeg()

public int Id { get; set; }
public string Naam { get; set; }
public string Icon { get; set; }

When one of the properties change, I'd like to do a notifypropertychange. Is this possible somehow without editing this generated class?

Answer Source

It would be possible, but I strongly suggest to not do this! Adding INotifyPropertyChanged in your model will lead to a bad separation of concerns.

Use events to highlight that the model has changed. Have a look here to see how this works: MSDN on standard event pattern

Or even better: MSDN cites Albahari Bros on the event pattern

In your viewmodel, implement INotifyProperty changed. Let your ViewModel than listen to the events from your model, adapt the data and push it to your view through INotifyPropertyChanged

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download