I found what I believe is bug with the code generation template for a C# entity. It is subtle. The basic idea is that two lines need to be switched in the order for the generation.
DB model:
- Book table.
- Reference table.
- Int ID
- Int RefBookID (foreign key to Book table)
The generation options: (most relevant are in bold)
- Generate single file
- Target Multiple Databases
- Metadata class should ignore schema
- Metadata class should ignore catalog
- Generate Hierarchical Model
- Support INotifyPropertyChanged
The resulting generated code.
Code:
1 virtual public System.Int32? RefBookID
2 {
3 get
4 {
5 [...]
6 }
7
8 set
9 {
10 if(base.SetSystemInt32(BookMetadata.ColumnNames.ShareSurveyID, value))
11 {
12 this._UpToBookByRefBookID = null;
13 this.OnPropertyChanged("UpToBookByRefBookID");
14 this.MarkFieldAsModified(BookMetadata.ColumnNames.RefBookID);
15 if (PropertyChanged != null)
16 {
17 PropertyChanged(this, new PropertyChangedEventArgs(BookMetadata.PropertyNames.RefBookID));
18 }
19 }
20 }
21 }
22
The issue is that Line 13 comes before Line 14. The problem with this is that a binding source may be notified that a change has occurred before the object itself knows that there was a change. The "this.es.IsDirty" will return false when on line 14 but events will already have fired.
The fix is just to generate line 14 before line 13. When I hand changed my generated class and tested it I got behavior I expected.
I hope this is enough information to explain the issue.
-Mark E.