It's not a small problem...
AdamRobinson wrote:
Unless you do something different in sub entity types, the overload of SetNewFieldValue that the overriden version in an entity calls is not virtual (as you may remember from our previous epic discussion!), so it would have to call the EntityBase version, since that is the only version.
Then again, if you DO do something different for inherited entities, just ignore what I just said!
I don't do anything different in de inherited entities. Let me explain what's happening
hierarchy:
entitybase
employee
manager
say employee calls base.SetNewFieldValue(3). SetNewFieldValue(3) is the virtual method which simply calls SetNewFieldValue(4) which does the actual work.
Ok, now manager also simply calls base.SetNewFieldValue(3). This happens to be employee.SetNewFieldValue(3). In the generated versions, these methods fire change events and make sure related references are reset if an fk is changed.
this works, UNTIL manager overrides a field of employee. In that situation, like with 'id', the change event will be fired twice: once from employee.SetNewFieldValue() and once from manager.SetNewFieldValue().
Though if you set the value through an instance of employee, you DO want the event. If you set the value through an instance of manager, you don't want the employee.SetNewFieldValue instance to do anything for that field.
That's why a derived SetNewFieldValue doesn't call it's base method. Though, this gives another problem, as shown in this thread: if a field in employee is set through a manager instance, the OnFieldChanged event isn't fired. What's worse: if the field is an FK, the reference of the related entity through that fk isn't reset. Well, it's a feature so it should work. It's not a big drama if it doesn't but if you rely on it, because it's a feature, you're in trouble, hence 'it's a problem'
The main issue with this is that the worker method is in the runtime lib, and the calling methods are in the templates. This means that a fix in the templates AND the runtimes requires customers to update both, which is not what should be done, as it requires a public api change on the runtimes and we avoid that at all costs IF it affects the templates, which such a fix does. I've to see how to solve this without major restructuring of this drama-method.