Domanda

I'm developing an Lightswitch app which has some kind of revision control. When a user changes an item and clicks save, instead of updating that row in the database I want a new row with the modified data and the original row reverted back to it's original state. I have managed to make new rows of the ones that got modified with this code:

        var changeSet = this.DataWorkspace.dataEntity.Details.GetChanges();
        var modified = changeSet.ModifiedEntities.OfType<RuleEntry>();

        foreach (RuleEntry re in modified)
        {

            //Create a new rule entry
            RuleEntry newRuleEntryRevision = this.DataWorkspace.dataEntity.RuleEntries.AddNew();
            newRuleEntryRevision.Country1 = re.Country1;
            newRuleEntryRevision.Family1 = re.Family1;
            newRuleEntryRevision.IP1 = re.IP1;
            newRuleEntryRevision.RuleKey = re.RuleKey;
            newRuleEntryRevision.RuleStatus = re.RuleStatus;
            newRuleEntryRevision.Title = re.Title;
            newRuleEntryRevision.Edited = DateTime.Now;
            newRuleEntryRevision.IsReal = false;

But after I've done that I want the "re" entity set back to the state it was before, in other words, it should have the values that's in the database.

I know it's possible to set the fields like this:

re.Country1 = Countries.Sweden;

And then just run SaveChanges(), but how do I get the right values from the database?

Thanks

È stato utile?

Soluzione

I did some manual digging and finally found it! The original value can be found like this:

re.Country1 = re.Details.Properties.Country1.OriginalValue;

Look at my first post to see what "re" is.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top