Answered SQLServer Update Trigger - Reflect changes in LS

  • Thursday, April 26, 2012 9:16 AM
     
     

    Hello,

    if I use an update trigger and make some changes in the current row (Data columns = GetDate()...) these changes will not reflect in LS.

    will LS not automatically resync the updated row to reflect changes which where made through triggers?

    if not how to refresh the current row after update?

    robert

All Replies

  • Thursday, April 26, 2012 10:31 AM
     
     

    I don't think you can refresh the current row but you can refresh the dataset (the table) or the datasource (all tables).

    You would probably call the dataset's Refresh method from the screen's Saved event.


    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.

  • Thursday, April 26, 2012 10:44 AM
     
     

    I'm wondering that such a fundamental functionality is not supported in LS because many people use triggers and default values in SQLServer.

    The only thing i found is to use the Refresh on the object (Table?) in the Saved event but these forces the screen/grid/details whole refresh and the selected row is moved to the first row...

    what I need is only a refresh/resync of the rurrent row (in ADO there is a resync method to do this)

    robert

  • Thursday, April 26, 2012 10:49 AM
     
     

    LS doesn't support this because it is designed for inexperienced people to make simple systems. It has its own way of setting defaults and of intercepting the "Save Pipeline" to make changes to this and other entities as they are saved.

    It may be that this scenario isn't supported by Entity Framework, on which LS is built.

    You could remember the key of the current SelectedItem and reposition the SelectedItem after refreshing the collection.

     

    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.

  • Thursday, April 26, 2012 10:55 AM
     
     

    I disagree in this point because LS primary Database is SQLServer and it should give us a possibility to use standard SQLServer functions.

    Refreshing the current row or select the row after DB Update is a "standard" since ADO Classic...

    are you sure that there is no possiblilty to do this?

    robert

  • Thursday, April 26, 2012 12:23 PM
     
     
    I do not want to auto refresh another users data - the only thing I want is to have a possibilty to refresh the current row and not the whole set of data...
  • Friday, April 27, 2012 6:04 AM
     
     

    Hello Simon,

    I'm able to save the Key for the selecteditem but how to do the "reposition" because there is no find or a similar method

    to go to the right row?

    robert

  • Friday, April 27, 2012 8:53 AM
     
      Has Code

    You set the SelectedItem to be the item it was before. How you do this depends on your exact circumstances.

    I've done it before in a kind of brute force method (because I needed a generic routine) but it works.

    colItems.SelectedItem = GetItemByKey(colItems, strKeyName, objKeyValue)
    
    Friend Function GetItemByKey(ByVal colItems As IVisualCollection, ByVal strKeyName As String, ByVal objKey As Object) As IEntityObject
     
        For Each objItem As IEntityObject In colItems
     
            If objItem.Details.Properties(strKeyName).Value = objKey Then
                Return objItem
            End If
     
        Next
     
        Return Nothing
    End Function


    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.

  • Saturday, April 28, 2012 1:27 AM
     
     

    I disagree in this point because LS primary Database is SQLServer and it should give us a possibility to use standard SQLServer functions.

    Refreshing the current row or select the row after DB Update is a "standard" since ADO Classic...

    are you sure that there is no possiblilty to do this?

    robert


    Currenlty the Default Database is SQL Server Based, but the Lightswitch system is designed to use any Entity Framework Provider supported database, for example you can have a provider for Oracle and it could connect to that... I do not know why but someone could write a provider for Access and it would support that. The system can also have Sharepoint as a datasource, so with that in mind the system would need to use the base functions that are availible in all of the different formats, just designing it for sql server would be limiting.
  • Saturday, April 28, 2012 5:51 AM
     
     

    so with that in mind the system would need to use the base functions that are available in all of the different formats, just designing it for sql server would be limiting.

    I believe that this is the reason LightSwitch does not support triggers, meaning they could if they wanted to :)

    I would also suggest that triggers are really not a good idea because you are splitting up business logic among multiple layers and triggers can affect sql server performance.

    I go way back to SQL Server 97 so I have been using triggers for years, but we used triggers back when we were coding cold fusion and asp+ pages (later they became asp pages then classic asp pages). At that time triggers were the best thing with the best performance.

    ... that was long time ago :)

    Just set the date for a field in the _Created event for an entity.


    The Visual Studio LightSwitch Marketplace

    http://LightSwitchHelpWebsite.com

  • Saturday, April 28, 2012 5:59 AM
     
     Answered

    LS doesn't support this because it is designed for inexperienced people to make simple systems. 

    That may be what some marketing people have said in the past, but that is not something I can agree with :)

    I have nearly 60 projects with source code showing professional applications built with LightSwitch like:

    Help Desk: An Advanced Visual Studio LightSwitch Application

    Using the ComponentOne Excel for Silverlight Control with LightSwitch

    A Full CRUD LightSwitch JQuery Mobile Application

    A Full CRUD DataJs and KnockoutJs LightSwitch Example Using Only An .Html Page

    Shape Your LightSwitch OData Using WCF RIA Services


    The Visual Studio LightSwitch Marketplace

    http://LightSwitchHelpWebsite.com