I know I can use ObjectContext instead, but I like the features of DbContext / DbSet. My application isn't large enough to warrant me writing complex view models, so I'd like to implement change notification on the EF generated models directly.
How can I achieve this?
This can be achieved by replacing the default T4 template (the .tt file automatically added by Entity Framework) with the following, then right clicking the .tt file and selecting "Run Custom Tool".
Important: This will regenerate your models which will cause any customizations to be discarded. I recommend you implement your customizations via the template rather than modifying the model class directly to prevent this from being a problem in the future.
Note: Replace
string inputFile = @"MessageLog.edmx";
with the name of your edmx file.I've had great success using a NuGet package called PropertyChanged.Fody to get INPC implemented on the entity classes. Just install the package, then add the [ImplementPropertyChanged] attribute to any class and PropertyChanged.Fody will "inject" INPC into the class as part of the build process. For example if you have a generated entity class called Customer, just add the following code somewhere in your project.
There are other attributes you can use to control the behavior of the PropertyChanged package. See https://github.com/Fody/PropertyChanged for details.
Peronally I have some troubles with Fody's implementation maybe this post could help you T4 Personalization
NOTE: It Works with EF 6.1 to.
I also had problems. Here's my implementation that works with 6.1.2. Clearly the problem with this solution is that each change in EF is going to require a new tt script. Perhaps Microsoft could provide different options that provide different levels of support.