locked
Best practice Value and DisplayName RRS feed

  • Question

  • What is best practice in assigning  values and displaynames ?

    Currently I'm using 1,2,3 etc for values and choice1 , choice2 , choice3 for displaynames. Guess I choose to do this because of some issues with searchable count limit. 

    I created a simple audit trail and its showing values. Is there a way to display displayname assoicated to the value ? 


    Wednesday, April 4, 2012 5:29 AM

Answers

All replies

  • Can you provide some more details on what you are doing here? So you have an entity with a choice list which I get but am not sure of the following

    1. How did you create your audit trail, how/where are you storing the audit data?
    2. How are you displaying the data?

    I am assuming you are storing the audit trail in another database table with a "ChoiceValue" column? In your display can "Add additional data" and do similar to this AuditTrailEntity.ParentEntity.ChoiceColumn.DisplayName?

    I'm not sure if that will work as I don't use the built in choice lists much. IMO it is always better to use a related table in the database design as is easier to walk the entities for display. Plus you have the added benefit of being able to add a new choice at any time without changing code which over time can help reduce maintenance time and costs.

    Unfortunately I'm not really seeing anything on the web with people doing a lot on this so hope this helps.


    MS Developer Guy

    Wednesday, April 4, 2012 3:28 PM
  • 1) I have just followed this tutorial including creating a new table for storing the changes.

    http://blogs.msdn.com/b/bethmassi/archive/2011/06/22/how-to-create-a-simple-audit-trail-change-log-in-lightswitch.aspx

    2) 

      partial void PatientsTelephoneFollowupDetails_Updating(PatientsTelephoneFollowupDetail entity)
            {
    
         var change = entity.TelephoneStatusLogs.AddNew();
         change.ChangeType = "Updated";
         change.PatientsTelephoneFollowupDetail = entity;
         change.UpdateTime = DateTime.Now;
        
    
         var newvals = "New Values: ";
         var oldvals = "Old Values: ";
         foreach (var prop in entity.Details.Properties.All().OfType<Microsoft.LightSwitch.Details.IEntityStorageProperty>())
    
        {
    
    		if (prop.Name != "Id")
    		{
    			if (! (object.Equals(prop.Value, prop.OriginalValue)))
    			{
                    oldvals += string.Format("{0}{1}: {2}", Environment.NewLine, prop.Name, prop.OriginalValue);
                    newvals += string.Format("{0}{1}: {2}", Environment.NewLine, prop.Name, prop.Value);
    			}
    		}
        }
            change.OriginalValues = oldvals;
            change.NewValues= newvals;
            }

    I would like to display prop.OriginalValue and prop.Value display names instead of values. Or may be I took wrong step and named values and display names differently. Hence I was thinking usually how other developers do considering future changes,requirements.  

    Thursday, April 5, 2012 1:31 AM
  • hmmm... i'd have to try this out but can you access the related information from the property? Something like:

    if (prop.Name == "MySelectionListProperty")
    {
    if (! (object.Equals(prop.Value, prop.OriginalValue)))
    {
                    oldvals
    += string.Format("{0}{1}: {2}", Environment.NewLine, prop.Name, prop.OriginalValue.displayname);
                    newvals
    += string.Format("{0}{1}: {2}", Environment.NewLine, prop.Name, prop.Value.displayname);
    }
    }

    Here is a check that i have in my application that does similar. My app has a Party Request and Party Status and I'm going through the entity properties to find PartyStatus property >> original value >> Party Status Id. In this case i could easily have gotten "Description" instead of "PartyStatusID". I'm using a PartyStatus table from Database that has HK/PK relationship rather that a set a choice list built in the entity designer though and so hope this works for you.

    if (entity.PartyStatu.PartyStatusID != entity.Details.Properties.PartyStatu.OriginalValue.PartyStatusID)
    {
        try
        {
            this.SendPartyEmail(entity);
        }
        catch (Exception ex)
        {
            //ToDo - Write to system log here
        }
    }


    MS Developer Guy

    Thursday, April 5, 2012 3:49 PM
  • Nope I couldn't access the related information from the property. Any other alternative than renaming values and displaynames same ?
    Friday, April 6, 2012 4:14 AM
  • Justin Andersen provided once a neat extension method for getting the displayvalue from a choicelist.

    See in the beta forum:

    http://social.msdn.microsoft.com/Forums/en-IE/lightswitchgeneral/thread/72b077f9-92fe-4405-84d0-e85f5fd5aa21

    paul.


    paul van bladel

    • Marked as answer by jonnagaddala Friday, April 6, 2012 7:14 AM
    Friday, April 6, 2012 6:57 AM
  • Paul this is exactly what I'm looking for. Thanks a ton. 
    Friday, April 6, 2012 7:13 AM