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

blog comments powered by Disqus

Blog3ngine dot NET 1.6.1.2
Theme by Daniel Halan

About the author

Daniel Halan Daniel Halan, M.Sc. systems architect in Sweden.

Working primary with Microsoft .NET, Dynamics CRM, XRM & Web Read more...

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


Follow Me
Yep, and filed under 'Worst Practice' @KentBeck: learning *why* it didn't work is almost as good as learning *that* it did work 25 Feb 2011

Microsoft Dynamics Salary Survey 2012

Nigel Frank International would like to invite you to complete our annual survey of global Microsoft Dynamics salaries. The survey will only take a couple of minutes to complete and your response and any personal details will be kept strictly confidential.

Prizes,
1st  iPad2 16gb Wi-Fi + 3G 
2nd Xbox 360 + Kinect 
3rd Kindle Keyboard w/ Free 3G + Wi-Fi 
4th MS LifeCam Studio Webcam 
5th MS Arc Touch Mouse 

You will also receive a FREE copy of the Salary Survey report once it has been compiled. 

Take the Salary Survey 
The survey is available in 12 languages for your convenience.