Skip to content

How to implement OnPropertyChanged

Simon Hughes edited this page Feb 5, 2020 · 8 revisions

In <database>.tt, approx. line 246 set the table base class:

Settings.UpdateTable = delegate(Table table)
{
    table.BaseClasses = " : INotifyPropertyChanged";
};

In <database>.tt, approx. line 96 set:

Settings.AdditionalNamespaces = new List<string> { "System.ComponentModel" , "System.Runtime.CompilerServices" };

In EF.Reverse.POCO.v3.ttinclude, approx. line 14818 set:

public string WriteInsideClassBody()
{
    return "    public event PropertyChangedEventHandler PropertyChanged;" + Environment.NewLine +
           "    protected virtual void OnPropertyChanged([CallerMemberName] string name = null)" + Environment.NewLine +
           "    {" + Environment.NewLine +
           "        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));" + Environment.NewLine +
           "    }" + Environment.NewLine;
}

In EF.Reverse.POCO.v3.ttinclude, approx. line (ef6 = 16199, efcore = 17411 ) The placement is under the function public override string Poco() Search for public {{#if OverrideModifier}}override {{/if}}{{WrapIfNullable}} to find the right place. Set:

    private {{WrapIfNullable}} _{{NameHumanCase}};{{#newline}}
    public {{#if OverrideModifier}}override {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get { return _{{NameHumanCase}}; } {{PrivateSetterForComputedColumns}}set { if(value != _{{NameHumanCase}}) { _{{NameHumanCase}} = value; OnPropertyChanged(); } } }{{PropertyInitialisers}}{{InlineComments}}{{#newline}}

Save EF.Reverse.POCO.v3.ttinclude, then save <database>.tt

Clone this wiki locally