locked
how to know previous value on Updating event RRS feed

  • Question

  • I need to implement side effect of a column update if another column is changed. I could create a trigger with this logic:

    update <mytable>
    set <fieldName> = null
    where inserted.<fieldname2> <> deleted.<fieldname2>
    How could I do the same in Ligthswitch?

    Tuesday, May 14, 2013 4:54 PM

Answers

  • Hi,

    In LIGHTSWITCH, any Entity's Property will also have a corresponding 'details' property object that contains extra information about that property, such as whether the property was changed, the original value, etc.

    For example in the Updating event I can do the following

    partial void Customers_Updating(Customer entity)
    {
        var companyProperty = entity.Details.Properties.CompanyName;
        if (companyProperty.IsChanged) {
            var originalValue = companyProperty.OriginalValue;
            var currentValue = companyProperty.Value;
        }
    }

    I think that will help with your scenario.

    Best regards,
    Huy

    • Marked as answer by Ragoran Thursday, May 16, 2013 8:58 PM
    Wednesday, May 15, 2013 5:17 PM

All replies

  • Hi,

    In LIGHTSWITCH, any Entity's Property will also have a corresponding 'details' property object that contains extra information about that property, such as whether the property was changed, the original value, etc.

    For example in the Updating event I can do the following

    partial void Customers_Updating(Customer entity)
    {
        var companyProperty = entity.Details.Properties.CompanyName;
        if (companyProperty.IsChanged) {
            var originalValue = companyProperty.OriginalValue;
            var currentValue = companyProperty.Value;
        }
    }

    I think that will help with your scenario.

    Best regards,
    Huy

    • Marked as answer by Ragoran Thursday, May 16, 2013 8:58 PM
    Wednesday, May 15, 2013 5:17 PM
  • Huy,

    Works perfectly.

    thanks

    Thursday, May 16, 2013 8:59 PM