-
Notifications
You must be signed in to change notification settings - Fork 226
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
- Home
- Compared with the Microsoft scaffolder
- Connection strings
- JetBrains Rider
- Upgrading from v3 to v4
- Saving .tt does nothing
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets