thespot4sap.com independent sap information
 

get SAP Access - pay monthly

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

Use LINQ to access CRM objects

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : SAP CRM
Blogged date : 2008 Aug 29

If you have written small console application to check some data from CRM database you have probably already read this article from MSDN: Use Filtered Views. That is okay but honestly I’m currently more into LINQ solution. I’ll show you what I mean...

First I'll create new Console Application project and Add New Item to it and select LINQ to SQL Classes and name it CRMDataClasses.dbml:
LINQDataClasses

Then I'll use Server Explorer to connect to CRM database:
ServerExplorer

And then I'll drag Account, Contact, FilteredAccount and FilteredContact to the canvas of our newly created CRMDataClasses.dbml: CRMDataClasses

Now I'm ready to use LINQ to these views:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
CRMDataClassesDataContext dataContext = new CRMDataClassesDataContext();

var queryContact = from contact in dataContext.Contacts
          where contact.MobilePhone.Length > 0 &&
          contact.LastName.Length > 0
    select contact;

Console.WriteLine("Contact(s):");
foreach (Contact c in queryContact)
{
  Console.WriteLine(c.FirstName + " " + c.LastName + ", " + c.MobilePhone);
}

var queryFilteredContact = from contact in dataContext.FilteredContacts
          select contact;
Console.WriteLine("");

Console.WriteLine("Filtered contact(s):");
foreach (FilteredContact c in queryFilteredContact)
{
  Console.WriteLine(c.lastname);
}

On lines 3 to 6 I queried all contacts that have lastname and mobilephone filled in. On lines 14 to 15 I'm querying all contacts where current user has access to. NOTE: It doesn't return anything if you use SQL Authentication! So both of these can be used to fill you applications needs. But do notice that for some reason the attributes at the FilteredContacts are all lower case and in Contacts their naming is a bit different. So if you plan to change from Contacts to FilteredContact your going to have to change the casing of the attributes little bit.

This was just quick advice how you can leverage LINQ to your CRM solutions.

Anyways... Happy hacking!

J


Read comments or post a reply to : Use LINQ to access CRM objects
Page 456 of 5579

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