locked
Usage of Retrieving DynamicEntity with SDK DLLs RRS feed

  • Question

  • Hi All,

    I am using SDK dlls in one of the web application that need to be hosted on ISV folder. I am trying to retrieve the data for a custom entity using the RetrieveRequest. I am getting the 'DynamicEntity' as output. But how to retrieve the data from this DynamicEntity. SDK points to some samples like 

    if (entity.Properties[i].Name.ToLower() == "fullname")

    { StringProperty property = (StringProperty) entity.Properties[i];

    fullname = property.Value; break; }

     

    But in SDK is mentioned as 

    using CrmSdk;

    using Microsoft.Crm.Sdk.Utility;

     

    What are they, how can i add reference to those namespace?

    Without that it wont allow to mention as 

    webLeadEntity.Properties[0].Name

    Name doesnt seem to be a property at all, instead Properties[] is only able to take string as input.  SO i am trying as below

    StringProperty wlSalutation = (StringProperty)webLeadEntity.Properties["salutation"];

    string salutation = wlSalutation.Value.Trim();

    Now it is giving exception as 

    Unable to cast object of type 'System.String' to type 'Microsoft.Crm.Sdk.StringProperty'

     

     

    Wednesday, March 9, 2011 3:40 PM

Answers

  • When you access a property from a Dynamic Entity's PropertyCollection, you are returned the value of the Property, rather than a Property object.  So in your example, it will look like:

    string salutation = (string)webLeadEntity.Properties["salutation"];
    

    For a CrmNumberProperty, for instance it will look like:

    int number = ((CrmNumber)entity.Properties["numberattribute"]).Value;
    
    Confusing initially, but a convenience once you know how it works.


    --pogo (pat)
    Thursday, March 10, 2011 1:15 AM

All replies

  • You can get the SDK here.  I am assuming since you are mentioning DynamicEntity that you are using 4.0 but I will include the SDK links for both.

    for CRM 4.0: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=en

    for CRM 2011: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=420F0F05-C226-4194-B7E1-F23CEAA83B69

    There is an included Bin folder that has the DLLs you need to reference.

    In Visual Studio you can add reference to them.  How to for adding references is below.

    http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx

     

     


    Jamie Miley
    Wednesday, March 9, 2011 4:29 PM
    Moderator
  • When you access a property from a Dynamic Entity's PropertyCollection, you are returned the value of the Property, rather than a Property object.  So in your example, it will look like:

    string salutation = (string)webLeadEntity.Properties["salutation"];
    

    For a CrmNumberProperty, for instance it will look like:

    int number = ((CrmNumber)entity.Properties["numberattribute"]).Value;
    
    Confusing initially, but a convenience once you know how it works.


    --pogo (pat)
    Thursday, March 10, 2011 1:15 AM
  • Ah, something very strange!

    It is working as you have mentioned pogo, thanks very much.

    Just to understand this further, why the examples in SDK are given that way? should we have to do something else to make it work in that manner?

     

    Thursday, March 10, 2011 6:06 AM
  • I've never actually seen that usage before; however I'm guessing it is the difference between the SDK libraries and the WSDL generated web service versions of the Dynamic Entity class.  Yup, just verified it.

    The WSDL generated DynamicEntity contains a Properties member that is declared as a Property array:

    Property[] Properties;
    

    The CRM SDK library (Microsoft.Crm.Sdk) declares the Properties member of Dynamic entity as a PropertyCollection:

    PropertyCollection Properties;
    


    --pogo (pat)
    Thursday, March 10, 2011 10:46 PM