Debugging LINQ-to-DASL Queries

When your LINQ-to-DASL queries do not return the results you expect, how do you determine where the problem is?  The issue could be that the query simply doesn’t do what you expect.  For example, you could be querying the wrong DASL properties and therefore Outlook returns no (or unexpected) items.  (This is easy to do,…

3

Filter Outlook Items by Date with LINQ to DASL

I received an email over the weekend asking why the following LINQ to DASL query threw an exception: Outlook.Folder folder = (Outlook.Folder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); var appointments = from item in folder.Items.AsQueryable<Appointment>() where item.Categories.Contains(“Personal Appointments”) && item.Item.Start.Date >= DateTime.Now – new TimeSpan(30, 0, 0, 0) select item.Item; foreach (var appointment in appointments) { MessageBox.Show(appointment.Start.ToString()); } The query looks…

8

LINQ to DASL Walkthrough

Now that the Office Interop API Extensions have been released, I thought I would post a complete walkthrough of a simple LINQ to DASL application. Let’s start with my fictitious Outlook calendar: This calendar shows that I have four appointments today. The appointments have been categorized as either “Work” (blue) or “Personal” (green). Suppose I…

0

Extending LINQ to DASL with Custom DASL Properties

In an earlier post I discussed LINQ to DASL, part of the Office Interop API Extensions, which is one of the forthcoming VSTO Power Tools.  LINQ to DASL allows you to write LINQ expressions against Outlook item collections.  I also mentioned that many known DASL properties were not mapped to their Outlook item equivalents in…

4

Using LINQ with the Office Object Model

In my last post I talked about LINQ to DASL, a LINQ provider that converts query expressions into their DASL equivalent in order to efficiently filter item collections in Outlook.  But LINQ to DASL solves only a very specific problem for one particular application.  The Office object model has many types of collections that we might like…

1

Query your Outlook Inbox with LINQ to DASL

Quick, tell me what the following code does: Outlook.Folder folder = (Outlook.Folder) this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); string subject = “VSTO”; string filter = @”@SQL=(“”urn:schemas:httpmail:subject”” LIKE ‘%” + subject.Replace(“‘”, “””) + @”%’ AND “”urn:schemas:httpmail:date”” <= ‘” + (DateTime.Now – new TimeSpan(7, 0, 0, 0)).ToString(“g”) + @”‘)”; Outlook.Items restrictedItems = folder.Items.Restrict(filter); foreach (Outlook.MailItem item in restrictedItems) { System.Diagnostics.Debug.WriteLine(String.Format(“Body: {0}”, item.Body));…

14