CRM 2011 Early Bound Entities Serialization / Deserialization

Hi all,

Just want to tell my experience regarding this topic - maybe it will save your time.

Crmsvcutil gives you generated entities file which can be a time saver. This is all good until you want to use those entities on client side (in my case I want to bring them to my knockout JS functionality combined with AJAX and web services to provide better user experience)

Serialization = works fine (when I retrieve the records).
The trick is to use JSON .NET , and with the help of Partial class you can extend the generated entity class from crmsvcutil. To get all properties serialized you need to use the [JsonObject(MemberSerialization.OptOut)] attribute on that partial class as well.

Deserialization = The problem appears when you try to deserialize (when I try to save the records).
The AttributeCollection class becomes the culprit in this, complaining that it Cannot create and populate list type of AttributeCollection.
Looking at the JSON Stringify ajax data that get passed from the page it seems that the Attributes collection is marked inside an array object creating this issue.

Long story short, since I don't want to modify the file generated by crmsvcutil, I decided to create intermediary classes for the entities that I need to work with. This might be a cleaner solution since you just focus on the attributes you want rather than getting the whole entity properties.

So, if you just want one way communication to show CRM records, serializing the generated class will work. However if you want to save back into CRM, you will have to create middle layer class to avoid this AttributeCollection problem and map the properties as you need.

Of course if anyone has similar experiences and know how to get around it please let me know ^_^

HTH,
Andreas

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline

Sitecore custom publish agent from specific node and at a specific time