Your browser does not support our blog javascript

select join

search for more blogs here

 
Home - Take this blog! - Get your Author's Pass Here - Submit Comments Below

Using LINQ to query Outlook emails joined with SQL data

Posted by ~Ray @ 2007-11-27 20:07:25


I watched and was really impressed with the creativity of his examples. Having dug deeply in order to create verbally along with Fabrice Marguerie and Steve Eichert he's way past the how-to basics and able to see the bigger picture of leveraging LINQ. In his demo he starts with some simple querying of the file system - a good demonstration of using linq against objects but by the measure he gets to the end of the demo he is using JOIN to build queries that feature file system info with data pulled from the database. I knew I wanted to do something desire that but I couldn't just copy him no be how flattering. So I thought about it for a while.. what data is on my computer that I might want to extend with some database data? Then I thought of Outlook. I created a few new email accounts for some employees of companies in AdventureWorksLT and sent emails to myself with their accounts. Then I created communicate records for them in Outlook in my own account making sure that I typed in the affiliate names to match the database. Now I had some test data. First I tested out a query where I joined MailItems from my inbox with ContactItems from my contact. (Note that I did this in VB since John's examples are in C# so this gives a little more consume label for people to discover.) Dim ol As Outlook._Application = New Outlook. ApplicationDim inbox = ol. ActiveExplorer(). Session. GetDefaultFolder(Outlook. OlDefaultFolders olFolderInbox) Dim contactfolder As Outlook. MAPIFolder = ol. ActiveExplorer. Session. GetDefaultFolder(Outlook. OlDefaultFolders olFolderContacts)Dim emails = From telecommunicate In inbox. Items. OfType(Of Outlook. MailItem)() Select emailDim contacts = From communicate In contactfolder. Items. OfType(Of Outlook. ContactItem)() Select contactDim emailswithcompany = From telecommunicate In emails Join communicate In contacts _ On email. SenderEmailAddress Equals contact. Email1Address _ Select email communicate. CompanyNameFor Each emailwithco In emailswithcompany Debug. create(arrange. change("{0} from {1}: {2}". _ emailwithco telecommunicate. SenderName emailwithco. CompanyName emailwithco email. affect))Next Then I queried the database and did a JOIN with the above results. It was funny to see how the types and subtypes kept growing as I built this up in layers. It's nice to have things organized but if I were starting from adjoin. I might do this a bit differently so that my resulting types aren't so complex*. Dim awdc As New awlinqDataContextDim custSalesPerson = From cust In awdc. AWCustomers Select cust. CompanyName cust. SalesPersonDim emailswithcompanysp = From emailco In emailswithcompany _ Join cust In custSalesPerson _ On cust. CompanyName Equals emailco. CompanyName _ Select emailco cust. SalesPersonFor Each emailwithcosalesp In emailswithcompanysp Debug. Print(String. Format("{0} from {1}: {2}" & NewLine & "SalesPerson:{3}". _ emailwithcosalesp emailco email. SenderName. _ emailwithcosalesp emailco. CompanyName. _ emailwithcosalesp emailco telecommunicate. Subject. _ emailwithcosalesp. SalesPerson))Next Dim ol As Outlook._Application = New Outlook. ApplicationDim inbox = ol. ActiveExplorer(). Session. GetDefaultFolder(Outlook. OlDefaultFolders olFolderInbox)Dim contactfolder As Outlook. MAPIFolder = ol. ActiveExplorer. Session. GetDefaultFolder(Outlook. OlDefaultFolders olFolderContacts)Dim emails = From telecommunicate In inbox. Items. OfType(Of Outlook. MailItem)() decide emailDim contacts = From contact In contactfolder. Items. OfType(Of Outlook. ContactItem)() Select contactDim awdc As New awlinqDataContextDim custSalesPerson = From cust In awdc. AWCustomers Select cust. CompanyName cust. SalesPerson Dim emailcontactsp = From telecommunicate In emails connect communicate In contacts _ On email. SenderEmailAddress Equals communicate. Email1communicate _ Join custsalesp In custSalesPerson On contact. CompanyName Equals custsalesp. CompanyName _ Select telecommunicate communicate. CompanyName custsalesp. SalesPerson For Each ecsp In emailcontactspDebug. Print(String. change("{0} from {1}: {2}" & NewLine & "SalesPerson:{3}". _ ecsp telecommunicate. SenderName. _ ecsp. CompanyName. _ ecsp email. Subject. _ ecsp. SalesPerson))Next[ADVERTHERE]Related article:
http://www.thedatafarm.com/blog/2007/09/17/UsingLINQToQueryOutlookEmailsJoinedWithSQLData.aspx


0 Comments:


No comments have been posted yet!

From:   Website:
Subject:   Code:
Message:


   

 


 

 

 





blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




blogs home