mikeg22 wrote:
Otis wrote:
...
So until the PK is finalized, e.g.: when the entity is actually saved, the PK isn't synchronized with childs.
Now, I'm not completely certain about your last remark, is the FK the PK of the child? (which wasn't clear to me)
The FK is the PK of the parent. The FK exists in the child entity and points to the parent. I think this is what you are asking but I'm not sure
No that's not what I was asking
. I meant: Employee with pk ID and Manager with pk ID. Manager's ID is an FK to Employee's ID, so Manager's PK is also an FK.
As for your example, the child entity already subscribes to the parent's AfterSave event, so why couldn't it subscribe to a PKChanged event or something like that? Is the problem just that subscribing to 2 events from the parent leaves more room for error (by not unsubscribing?)
Yes, it leads to more code, as PK's can have multiple fields, plus as the entity is still undefined, the FK shouldn't be set until the PK is defined, when the entity is defined, after the save. Because it can be that the PK is an identity, the FK should be synced afterwards, not beforehand, so you'll get inconsistend behavior: a non-defined PK is synced with its FK fields only if its not an identity field.
The event subscribing isn't the real issue, the non-defined PK is the real issue. Consider: you have a new entity and you add an existing entity as a child to that new entity. The FK in that existing entity changes. It's then dirty. But actually, it shouldn't be, as technically, the entity isn't really changed yet, because the save hasn't taken place. So it's a principle: where is the entity exactly defined, in the db or in memory. LLBLGen Pro builds on the concept that the entity is defined in the db. This means that a new entity doesn't really exist until it's saved succesfully. That's a core concept and thus pre-save synchronization can ONLY take place if the PK is defined with the entity, which is only the case if the entity is saved succesfully.