logo

Best practise: using _Changed methods

Home » Lightswitch » Best practise: using _Changed methods

Best practise: using _Changed methods

| Lightswitch | februari 11, 2013


Problem

Whenever a property in a related entity is read in code, Light Switch fires a change event on the parent, but doesn’t actually change any properties on the parent.

 Solution

Just put this code at the start of all _Changed methods and you are save. The code after that will only run when the entity has really changed.

c#

 if (this.Details.EntityState == EntityState.Unchanged || this.Details.EntityState == EntityState.Deleted
                || this.Details.EntityState == EntityState.Discarded ) return;

vb.net

If Me.Details.EntityState = EntityState.Unchanged OrElse Me.Details.EntityState = EntityState.Deleted OrElse Me.Details.EntityState = EntityState.Discarded Then
	Return
End If

 

About the author

Partner @ Firmware

3 Responses to "Best practise: using _Changed methods"

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *

De volgende HTML-tags en -attributen zijn toegestaan: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *

 Vraag het ons LIVE
Powered by PureChat.com