none
Using NotifyPropertyChanged in custom properties of DBContext RRS feed

  • Question

  • I am using a database first generated model in EF 4.1 and using the DBContext Generator to generate code.  I need to add a custom property to one of the data class and have the UI respond to changes to that custom property.  In the past using DataContext I would simply create the property and have it call OnPropertyChanging and OnPropertyChanged in the EntityObject class like:

    public partial MyTable : EntityObject
    {
       private bool _myProperty;
    
       public bool MyProperty
       {
          get { return _myProperty; }
          set {
             OnPropertyChanging("MyProperty");
             _myProperty = value;
             OnPropertyChanged("MyProperty");
          }
       }
    }

    This doesn't work with DBContext because the POCO classes created by the DBContext Generator don't implement EntityObject or INotifyPropertyChanged.  If I try implementing INotifyPropertyChanged in my partial class then my custom property works, but all of the DBContextGenerator generated properties of the class stop notifying the UI of changes.

    Does anyone know how to add a custom property to a DBContextGenerator generated class which will notify subscribers of changes?

    Mike Emerson


    • Edited by MikeEmerson Monday, March 19, 2012 12:07 AM
    Monday, March 19, 2012 12:06 AM

Answers

  • I think this article can help you.

    http://www.codeproject.com/Articles/269846/Visual-Studio-Template-for-generating-POCO-classes


    Fighting like Allen Iverson. Neve give up!

    Tuesday, March 20, 2012 4:11 AM