rosslotharius.com

The blog of Ross Lotharius.

August 2007 - Posts

Creating a Web Portal with CRM 3 and LINQ

I have been spending a decent amount of time reading up and playing around with the new features that are coming with Visual Studio 2008.  One site that I regularly read is Scott Guthrie's blog.  Lately he has been posting a lot about LINQ and I really like the idea behind the technology.  Having a more object oriented way of querying opens up a new realm of possibilities as well as makes life easier when writing code.  Intellisense is a wonderful thing!

Today, I'm going to be writing about using LINQ in combination with CRM's filtered views to create a very basic web portal that allows you to search for Accounts and display the name and primary Contact in a GridView.  I'll demostrate how simple it is to create the LINQ objects and hook into CRM's database all while being 100% supported and secure.  For those not familiar with CRM filtered views, they are basically a Microsoft supported way to query the database directly and still maintain security on the data.  So let's get started.

I started out by firing up the latest build of VS 2008 (Beta 2) and created a new web project on my pre-built CRM VPC.  After creating the project, I right clicked on the App_Code folder and chose to add a new item.  In the New Item list, displayed below, I chose LINQ to SQL Classes file and named it CRM.dbml.

After adding the new file I then went into the Server Explorer and connected to my Sql Server's MSCRM database.  I then opened up my CRM.dbml file and dragged the FilteredAccount and FilteredContact views from the Server Explorer.

*Notice that after you drag the views into the main window, they appear as a package with properties on them.  You can select each property (field) individually and set properties on them.  To increase the efficiency of the querying itself, fields such as "Delay Loaded" will only load the data for that field if it's used.  For more details on specifying properties check out Scott Guthrie's post here.

After adding the 2 filtered views, I added a TextBox, Button, and GridView Asp.Net controls to my Default.aspx.

*Another very cool feature coming with VS2008 is the split view display.  This display allows you to view the output page as you write the Html.  I find it handy for CSS updates and manipulating the page to get that exact look and feel.

I then opened the code behind and started writing my code on my "Find" button's onclick event.  By default the namespace System.Linq is added in my header and the intellisense immediately picked up.

protected void queryButton_Click(object sender, EventArgs e)

{

    if (search.Text != string.Empty && search.Text.Length > 0)

    {

            CRMDataContext db = new CRMDataContext();

            accountGrid.DataSource = from a in db.FilteredAccounts

                  join con in db.FilteredContacts

                        on a.primarycontactid equals con.contactid

                  where a.name.StartsWith(search.Text)

                  select new

                  {

                        Name = a.name,

                        PrimaryContact = con.fullname

                  };

           

            accountGrid.DataBind();

    }

}

The first line I added is my data context.  To reference my CRM filtered views, I simply type CRMDataContext.  I then set my DataGrid's (Id = accountGrid) DataSource to the LINQ query I am going to run against the object.  Notice how similar the query looks like Sql.  When creating the query, I joined my FilteredAccount to the FilteredContact to return the Primary Contact's fullname.  While typing the query the intellisense made it very easy to use.  I didn't have to go back to my view and see what the fields name were, they were right there.  One less Alt+Tab is a big plus in my book!  You can see it in the screenshot below.

 

After finishing my code, I hit save and ran my project.  Below are the results.

 

Here is the CRM view of the data. 

So there you have it.  CRM data displayed in a web portal, all supported and secure, using LINQ with VS 2008 and CRM's filtered views.

Update:  Michael Friis emailed me to let me know of a project he is currently working on relating to LINQ to CRM.  I suggest checking it out here

Posted: Aug 20 2007, 01:01 AM by Ross | with no comments
Filed under: , , ,
So What's to Come?

Over the next few weeks I plan to start posting all about my experiences with Microsoft CRM.  I plan to do a few write-ups on using some of the new features coming with Visual Studio 2008 "Orcas" with CRM 3.0.  I might also delve into using Sharepoint 2007 (MOSS) and Microsoft Windows Workflow Foundations but we will see.

If you have any requests on things you would like to see, please feel free to leave me a comment here and I will do the best I can to fit it in, or at least talk about it :-).

Vista Tips & Tricks for Better Performance

Windows Vista introduces many new features and gadgets that have made this operating system a fair amount slower and RAM intensive than Windows XP.  In this article, I will highlight some things I have done to improve the performance of Vista and cut down it's memory usage by almost half.

Disclaimer:  Making tweaks and adjustments to your machine should only be done by people with experience in operating systems.  These tweaks have not been thoroughly tested.

Details
 
  • Remember Each Folder's Settings (If you like to view pictures and what not differently, keep this enabled)

Windows Explorer > Tools > Folder Options > View

  • Uncheck 'Remember each folders settings'
    • I always use Details and default all of my folders to this.  Remember each setting is redundant for me.

 

  • Disable Aero features. 

When you first run Vista the Aero features appear great and awesome but after awhile they seem to make your system feel slower.  To speed up your system (especially legacy systems) and still keep the Aero look.

 

Goto Start > right click System >  Properties > Advanced System Settings > Advanced > Under Performance select Settings and uncheck the following:

 

  1. Animate windows when minimizing and maximizing; This removes the expanding animation when new windows open and instead instantly opens them and closes.  At first Vista looks cool when you min/max.  After awhile it feels sluggish, turning this off gives it that snappy instant feel again.
  2. Enable transparent glass; An eye candy feature that will bog down an older video adapters.
  3. Fade or slide menus into view; Another eye candy feature that's not needed.
  4. Fade or slide ToolTips into view; Another eye candy feature that's not needed.
  5. Fade out menu items after clicking; Another eye candy feature that's not needed.

 

Note: There are more options that can be turned off.  I chose these because they are the eye candy I am happy without.

 

            Update, Today I only have the following options checked 

  1. Enable desktop composition
  2. Smooth edges of screen fonts
  3. Use drop shadows for icon labels on the desktop
  4. Use Visual Styles on windows and buttons

 

 

  • Stop auto-start applications on startup

There are two ways to stop applications that start when you startup your computer at login. You can use the System Configuration Utility or the new Software Explorer in Windows Defender. Take a look at the two sections to get control over your startup applications and speed up your computer:

 

Disabling auto-start applications with the System Configuration Utility

  1. Click on the Start Button and key in msconfig and hit Enter.
  2. Click on the Startup tab.
  3. Remove the check next to any items that you do not want to startup and click OK.

 

Disabling auto-start applications with Windows Defender

  1. Click on the Start Button and type in Windows Defender and hit Enter.
  2. Click on the Tools from the top menu bar.
  3. Click on Software Explorer.
  4. Hit Show for All Users.
  5. Select an application and then click either Remove or Disable.

 

  • Turn off un-needed Vista services. 

The link to the following site is very helpful for identifying services to shutoff http://www.tweakhound.com/vista/tweakguide/page_7.htm

 

  • Registry Modifications

Turn off the low disk space checks:

  1. Using the left side of the Registry Editor, navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies
  2. Right-click in the right pane and select New Key.
  3. Name the new key Explorer.
  4. In the Explorer key, right-click in the right pane and click New DWORD (32-bit) Vaue.
  5. Name the DWORD NoLowDiskSpaceChecks.
  6. Right-click the new DWORD and click Modify.
  7. Set the Value Data to 1.
  8. Click OK.

This will prevent Windows Vista from checking the space on your hard drive and popping up the notorious 'Hey, you're running out of space!' warning balloon.

 

Next, you can probably safely disable the NTFS habit of creating 8.3 versions of filenames for backward compatibility. DOS is dead, right?

Open the Registry Editor and:

  1. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  2. Find the DWORD called NtfsDisable8dot3NameCreation.
  3. Right-click it and click Modify.
  4. Change the value to 1.
  5. Click OK.

 

 

  • Turn off User Account Control

This is the feature that always prompts you whenever you click anything.  It’s not a performance boost but rather annoyance.

Goto: Start > Control Panel > User Accounts > Select your user > Turn User Account Control on or off.

 

  • Use Vista

Vista monitors your computing habits and caches the stuff you use the most. It also moves things on the hard drive that it thinks you'll want to the fastest area of the platter. It does all kinds of background work to speed up, tune itself up, and make itself as responsive as it can be.

 

Use Vista regularly and, in about a week, it should be fully optimized based on what you do. Windows XP started the trend with its own self-optimization, but Vista truly gets it right. Vista's own optimization isn't perfect, but the steps in this article will boost it so that it's even more responsive and well-tuned.

 

 

References:

http://www.tweakvista.com

http://www.blackviper.com/WinVista/servicecfg.htm.

http://www.extremetech.com/article2/0,1697,2110605,00.asp

http://www.tweakhound.com/vista/tweakguide/index.htm


Posted: Aug 18 2007, 01:54 AM by Ross | with no comments
Filed under: ,