After spending a year working with the Microsoft.Xrm.Sdk namespace, I just discovered that the Entity.FormattedValues property contains a text value for Entity special objects (i.e. Local) yesterday.
The reason I didn't find it before is because the early binding method doesn't matter. that is, entity.new_myOptionSet is of type OptionSetValue , which contains only an int value. You must call entity.FormattedValues ββ["new_myoptionset"] to get the string text value for OptionSetValue .
Therefore, I would like to get crmsrvcutil to automatically create a text property for local parameter sets. those. along with entity.new_myOptionSet generated the way it currently does, Entity.new_myOptionSetText will also be generated.
I looked at Microsoft.Crm.Services.Utility.ICodeGenerationService , but it looks like it is mainly to indicate that CodeGenerationType should be something ...
Is there a way that supports the use of CrmServiceUtil to add these properties, or is it better for me to write a custom application that I can run that can generate these properties as a partial class for automatically generated ones?
Edit - sample code that I would like to generate
Currently, when I need to access the text value of the OptionSetValue parameter, I use this code:
var textValue = OptionSetCache.GetText(service, entity, e => e.New_MyOptionSet);
The options installation cache will use entity.LogicalName , and the property expression will determine the name of the parameter set I'm asking for. He will then query the SDK using RetrieveAttriubteRequest to get a list of set int options and text values, which he then caches, so he doesn't need to hit CRM again. He then looks at the int value of the New_MyOptionSet object and cross-references it with a cached list to get the text value of the OptionSet.
Instead of doing all this, I can just do it (assuming the object was received from the server, and not just from the filled client side):
var textValue = entity.FormattedValues["new_myoptionset"];
but "new_myoptionset" is no longer early. I would like the classes of the early linked entity that are generated to also generate an additional βTextβ property for the OptionSetValue properties that calls the above line, so my object would add the following to it:
public string New_MyOptionSetText { return this.GetFormattedAttributeValue("new_myoptionset"); // this is a protected method on the Entity class itself... }