This project is read-only.

Creating a CRM entity class

An entity in CRM can contain hundreds of attributes, but you might only be interested in working with a couple of them. In order to reduce the payload, you therefore need to specify which entities and attributes you are interested in. You do this by creating a class for each entity, specifying the attributes as properties.

First create a class for the entity, with a CrmEntity attribute. The CrmEntity attribute has one argument, the name of the CRM entity. In this example we want to create an entity class for the Contact entity:

 

[CrmEntity("contact")]
public class CrmContact
{
   // More to come
}

 

Now we need to specify the attributes we are interested in as properties of this class. You should always include a property for the ID attribute of the entity, even if you do not use it! Update operations will not work if you leave the property out! So let's add a couple of properties to the class above. The attributes we are interested in are ID, firstname and lastname, so we create three properties with a CrmAttribute attribute. The CrmAttribute attribute has one argument, the name of the CRM attribute: 

 

[CrmEntity("contact")]
public class CrmContact
{
   // Has to be included for update operations!
   [CrmAttribute("contactid")]
   public Guid Id
   {
      get;
      set;
   }

   [CrmAttribute("firstname")]
   public string FirstName
   {
      get;
      set;
   }

   [CrmAttribute("lastname")]
   public string LastName
   {
      get;
      set;
   }
}

Now you will be able to do CRUD operations on Contact entities, but you will only be able to read and update the firstname and lastname attributes of the contact. You will not be able to retrieve or update attributes such as address or phone number as these are not included in the class.

Summary

  • An entity class is decorated with the CrmEntity attribute
  • A property is decorated with the CrmAttribute attribute
  • You should always include a property for the id attribute of the entity

Last edited Oct 20, 2010 at 1:25 PM by karolikl, version 3

Comments

No comments yet.