Generics with CRM

by Daniel Halan 16. November 2009 23:17

Generics is a very nice feature of C# language, and can be used to simplify the CRM Web Service method calls. One of my responsibilities at Logica is to develop a framework for CRM development, and one of the main classes in this framework is called CrmSystem, it wraps the CrmService methods among other things. Using generics one can then type,

account acc = CrmSystem.Retrieve<account>(myAccountId);

also we use a special NameValue class CrmConditions to one of our Execute overloads, here is how it can look

List<account> acc = CrmSystem.Execute<account>(new CrmCondition("emailaddress1", "daniel@logica.com"));

This would retrieve all accounts that got the email "daniel@logica.com"

Here is one of the overloads for the Retrive Method that uses Generics, it calls an other overload that does the actual call to CRM Web Service using the EntityName string that we get thru typeof(T).Name


public
T Retrieve<T>(Guid id, params string[] columnSet) where T : BusinessEntity { 
     return
(T)Retrieve(typeof(T).Name, id, new ColumnSet(columnSet));
}

 

Hope this gives some inspiration for your own CrmApi wrappers :)

 

Tags: ,

.NET | CRM

Comments

11/21/2009 3:36:42 AM #

trackback

Generics with CRM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com | Reply

1/12/2010 9:24:47 AM #

trackback

Generics with CRM

Generics with CRM

Phil's CRM Blog | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Daniel Halan Daniel Halan solutions architect at Logica in Sweden.

Working primary with Microsoft Dynamics CRM.

Complete Profile

The content of this site are my own personal opinions and do not represent my employer's view in anyway.