This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am trying to use Lightspeed DTO's to perform some basic data synchronization, but I need to preserve ID fields when synchronizing my 'offline' local database (tables in my two databases match). Including the Id in the DTO is simple enough, but I don't see a way of setting this Id field prior to inserting this entity into the local database. What is the best strategy to handle this? I am attempting to preserve my data model, which I understand is not an ideal one for synchronization.
|
|
|
We've had a few enquiries about synchronising databases using LightSpeed recently, and we have to be honest, it's not the best fit for the job: if you can find a dedicated sync tool (e.g. if you are using SQL Server then check out the Sync Framework) then this will probably be easier than trying to deal with ID issues, changeset tracking, etc. in LightSpeed. However, we realise that researching and learning a potentially complicated new toolkit may be overkill for your application. So here is an outline of how you can use to set the ID prior to inserting the entity in the local database, but be warned it is a bit on the ugly side. First, you need somewhere to store the ID you want to assign. A transient field is probably the easiest candidate for this. (It must be transient or LightSpeed will go looking for a database column in which to store it.) Second, you need to populate this with the ID in environments where you want to control the ID. For example, you would populate the "ID holder" during DTO deserialisation (in your partial of the CopyTo method), but not when creating a new entity. Care may be required around DTOs for new entities sent from the client to the server (e.g. make sure you are using the GUID identity method, not a sequential method, so that IDs allocated on the various clients don't clash). Third, override the GeneratedId() method. In the implementation, check the "ID holder" and see if it has been populated. If it has *not*, call base.GeneratedId() to delegate to whatever LightSpeed identity method is in effect. If it *has*, then return the value of the "ID holder." As you can see, it's not pretty, but this isn't one of the scenarios for which LightSpeed was designed so it is working against the grain of the product to some extent. Hope this is useful to you all the same! |
|