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
|
Hi, Consider the following scenario: We have a very simple database with one table "Thing" and one string value, "Foo", which only contains string representations of integers i.e. "1", "78", "834" etc. Later we decide that it would be better to change "Foo" from a string to an int. In attempt to do this, we try the following:
So far, so good. We've got 2 columns in our table, "Foo" and "Temp". Foo being a string representation of an integer, and "Temp" being the actual int. Now we try do the following:
Now this is where it gets confusing. As soon as I change the model, to have Foo as an int instead of a string, then I can't compile my project anymore. Recall that previously we read a Foo string into a temp int. In order to do that we needed to parse the string. This doesn't work anymore since the Foo object is now an int, and not a string. I attach an example project that shows this. What is the correct way to handle the above scenario? When migrating, how do you preserve existing data? Please let me know if my question is unclear. Windows 7 SP 1, VS2012 Pro, LightSpeed 5.0.2587.0 |
|
|
There are a few ways to approach this but the simplest to my mind would be to drop the Foo column and rename the Temp column to Foo as a native command call prior to updating your Foo entity property to be an int. As part of the same migration you can then remove the Temp entity property. You will want to remove the generated code associated with applying those 2 changes to the database.
|
|
|
Hi Jeremy, I don't follow. Even if I use native commands to drop value and rename temp, my model will be out of sync. Updating the model then to reflect the schema of the database will still cause my code to not compile, since Temp will no longer exist in the model. Do you see the problem? Whenever the model changes, the coded needed to persist the data no longer compiles. Please dumb it down for me. Regards. |
|
|
Your process was:
-> I am suggesting you would perform the native command migrations here For the remaining steps you just need to
Because you have done the migration steps for the above two steps already via the native command call when you change the model to update Foo to be an int the underlying column is already set as an int so you wont have the coercion issue. Similarly the Temp column no longer exists in the table already.
|
|