thespot4sap.com independent sap information
 

get SAP Access - pay monthly

SAP Tutorials    Online SAP Training    SAP CBT's    Forums    SAP Articles    SAP Jobs    Resumes
  SAP Access    SAP Blogs    SAP Books     Links     Vendor Directory     Submit Content    Search
Previous posts in SAP CRM
Page 471 of 5166

Lambda expressions and anonymous methods on Metadata service in CRM 4.0

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : SAP CRM
Blogged date : 2008 May 08

In C# 3.0 Microsoft has added lambda expression. This is not a new feature in computer languages originally designed on a conceptualized level way back in time by an American called Alonzo Church.

Lamda expressions provide shorthand syntax for algorithms.

I have played around with this and below is a simple example where I retrieve all entities from the CRM metadata service. I call my filter method and provide my delegate with the filter expression. I have also an example on using anonym’s method, in previous versions before 2.0 you had to write a named method and pass that name where the delegate was required. The syntax for C# operator is => and lambda expression. Example is simple and I'm only using one param1 (filter) and checks if entity is customizable.

        static void Main(string[] args)

        {

            //Login and retrive all entities from metadataservice (change name to your org)

            RetrieveAllEntitiesResponse allEntitiesResponse = Metadata.RetriveAll("mydemo");

 

            //Lambda expression

            EntityMetadata[] filterEntities = Common.FilterMetadata(allEntitiesResponse,

                filter => (filter.IsCustomizable.Value == true)

                );

 

            /*

            //Anonymous method

            EntityMetadata[] filterEntities = Common.FilterMetadata(allEntitiesResponse,

                delegate(EntityMetadata filter)

                {

                    return (filter.IsCustomizable.Value == false);

                });

            */

 

            //Write result to console

            int total = 0;

            foreach (EntityMetadata item in filterEntities)

            {

                Console.WriteLine(item.SchemaName);

                total++;

            }

            Console.WriteLine("Return of record(s) {0}", total);

            Console.ReadKey();

 

        }

 

If your filter is complex you might consider to create a named method. I have attached Visual Studio 2008 project for you to play around with.

 

Lambda on MSDN

 

This posting is provided "AS IS" with no warranties, and confers no rights.

 


Read comments or post a reply to : Lambda expressions and anonymous methods on Metadata service in CRM 4.0
Page 471 of 5166

Newest posts
New Page 1

 

 

About Us   Contact Us   Privacy   Disclaimer   Feedback   Email Discussion   Newsletter  

Copyright © - Independent SAP Information
Learn XML, Guesthouses and B&B's