DvK wrote:
Just because you can make an entity object in memory look like a 'fetched' entity (while it's new), it doesn't mean you should use that as the recommended way to deal with data. I.o.w.: fetch the entities, modify them, save them. It's much easier to deal with the data that way: almost no code, everything works as expected and no surprises. I.o.w.: maintainable software.
We're dealing with a Silverlight application here which uses DTO objects (initial fetch) to display data in the GUI. That data can be modified by a user and then only the modified fields are being tracked by the application and send back to the WCF-layer as a 'modified fields' object. There, a 'new' entity (IsNew=False) is created by setting its PK value and the modified field values, and the save is performed using either a SaveEntity of UpdateEntitiesDirectly in order to make the UPDATE process as efficient as possible as we're only updating changed fields. That's what LLBLGen is all about, efficiency...not ?
Never pre-maturely optimize your code. It's not said that using entity fetches is less optimal, simply because from the looks of it, you have to fetch the data from the DB anyway, as you have to audit value changes.
So to me you'd better do:
- fetch the entities which were changed based on PK values specified in the change set received from the client
- update these entities with the values received from the client. This will mark fields which are changed to 'changed' and ignore field changes which aren't really field changes (e.g. another client altered the same field already!)
- simply save the entities again.
Very simple code and it works always and auditing is transparently build in. Less efficient? You can optimize this with checking before the fetch if you have altered a non-pk field F in entity type E and if not, exclude that from fetching. So if the client altered 3 customer entities and the client altered field F1, F2 and F5, you fetch the 3 customer entities with fields F1, F2, F5 and the PK and you alter the fields on the 3 entities, save them, done. this is as efficient as you would be with your own code as well, but it at the same time uses way less code and is easier to maintain.
Furthermore, fetching these entities really doesn't count compared to the overhead and slowness of a WCF channel.
This also doesn't need cumbersome code de-centralized somewhere, it's simple entity fetch logic and auditors are plugged in automatically. So I don't really see why you need monitoring code as it's just straight forward entity fetching/updating/saving.