locked
LightSwitch 2013 HTML Client - Changing a field name in SQL Server causes the screens to need rebuilding ... RRS feed

  • Question

  •  Hi,
       I am using visual studio 2013. I have a LightSwitch project that gets its data from my SQL Server.
       I had to change a field name in a SQL Server table from "iqSequence" to "lgSequence". when i did this, I refreshed the data Source and the NEW field showed up in the data source. After I re-built the project and ran it, my Add/Entry page would not work, it said that the "lgSequence" could not be empty. I looked at the screen and the "lgSequence" was not int the column list. but the new field was in the left pane available to be added.
       I looked at a backup of this project and i saw that "iqSequence" was in the column list in the backup. SO, it looks like once i changed the field name, it included the new field in the Data Source, but did not replace the old field in the screen.

       Also, another screen would just not work, i could not immediately find out why, but i just created another screen to replace it and it worked.

       Does this mean that when i make changes like this to SQL Server,I need to go to each screen using this field and put it back in the screen? stating the obvious, if i have a lot of screens with that field, then i have to manually add the field to each screen. Not a problem in the end, but maybe there is a way to add the field to all the appropriate screens all at once?  programatically, i know this could be onerous because a field name could be in so many places throughout LS code. you would almost need some kind of scan and replace. Anyway just trying to make sure there isnt something in LS that would allow this mass change that I have not learned yet.

        thanks for your time.


    david

    Friday, August 15, 2014 1:00 AM

Answers

  • Renaming a column in SQL Server is seen by LightSwitch as deleting a column and adding a new one. It does not consider data types and column orders to guess it might be a rename.

    Deleting a column causes the field to be removed from the model and so all the controls that depend on that field are also removed.

    Adding a column causes a new field to be added to the model but new controls are not created for that field automatically.

    This is expected behaviour.

    If the rename is the only change and you are sure of what you are doing, you could perform a search and replace on the LSML files in your solution to make them match the new SQL Server database schema rather than using LightSwitch's Update DataSource command but this is not recommended.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by iqworks Friday, August 15, 2014 8:33 PM
    Friday, August 15, 2014 8:48 AM

All replies

  • Renaming a column in SQL Server is seen by LightSwitch as deleting a column and adding a new one. It does not consider data types and column orders to guess it might be a rename.

    Deleting a column causes the field to be removed from the model and so all the controls that depend on that field are also removed.

    Adding a column causes a new field to be added to the model but new controls are not created for that field automatically.

    This is expected behaviour.

    If the rename is the only change and you are sure of what you are doing, you could perform a search and replace on the LSML files in your solution to make them match the new SQL Server database schema rather than using LightSwitch's Update DataSource command but this is not recommended.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by iqworks Friday, August 15, 2014 8:33 PM
    Friday, August 15, 2014 8:48 AM
  • thank you Simon, that explains it.

    david

    Friday, August 15, 2014 8:33 PM