This project is read-only.

Retrieving entities

There are three different ways of retrieving entities:

  • Get
  • Find
  • FindAll

All examples assume we have a CRM entity class, a CrmControllerFactory and a CrmEntityController.

Get

The Get method is used when you know the Guid of the entitiy you want to retrieve. An example of how you can get a Contact entity:

CrmContact contact = crmContactController.Get(guid);

Find

The Find method is used when you don't have the Guid of the entity you want to retrieve or if you want to query for several entities. In order to use the Find method you need to create a CrmQuery. This example shows how to use the Find method to get all Contacts whose first name is John:

CrmQuery query = new CrmQuery();
query.AddCondition(new CrmAttributeCriterion("firstname", "John", CrmConditionOperator.Equal));

List<CrmContact> contacts = crmContactController.Find(query);

You can also choose to set a sorting criteria to the Find method. This example shows how to find all Contacts whose first name is John (using the query above), sorted by last name descending:

List<CrmContact> contacts = crmContactController.Find(query, new CrmSortingCriteria("lastname", CrmSortOrder.Ascending));

At last, you can speficy paging criteria to the Find method. This example shows how to find the first 5 Contacts whose first name is John (using the query above):

int totalCount;
List<CrmContact> contacts = crmContactController.Find(query, 1, 5, out totalCount, null); 

As shown in the example above, you can speficy a null value for the CrmSortingCriteria if you don't want sorting.

FindAll

The FindAll method retrieves all entities of a type. This example shows how to find all Contacts:

List<CrmContact> contacts = crmContactController.FindAll();

Last edited Dec 3, 2012 at 2:34 PM by karolikl, version 8

Comments

No comments yet.