THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

Bug in generated entity with foreign key when using INotifyPropertyChanged?

rated by 0 users
This post has 2 Replies | 0 Followers

Top 200 Contributor
Posts 13
marke Posted: 04-21-2008 10:30 AM

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.
    • Int ID
  • 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.
 

Top 10 Contributor
Posts 3,881
Good catch, we will fix it.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 200 Contributor
Posts 13

Mike.Griffin:
Good catch, we will fix it.

 
Thanks! 

Page 1 of 1 (3 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC