blog.mha.dk
The on-line blog of Michael Holm Andersen

Using LINQ to join SQL table and in-memory collection

Friday, 18 January 2008 07:10 by mha

It's been on my TO DO list for quite some time now!! - "Upgrade the ASPNETHOTEL website!" .. So a couple of weeks ago, I decided to actually do something about it!

I'll be adding credit card payment, automatic retrival of customer address information, 3 different hosting plans, payment for 1-5 years with discount, a lot of minor changes, and last but not least - I've created a completely new design for the website.

The site will be build using VS2008, .NET 3.5 and LINQ. A couple of days ago I was working on the "domain check" functionality, which turned out to be a good opportunity to play around with some LINQ. Let me clarify:

I have a simple table in my database containing TLD (Top Level Domain, e.g. "dk", "com", etc.), prices and other stuff. When the user enters a domain (without TLD), I want to check wether the corresponding domains are free for registration. In order to check this, a call to the WhoIs server is made and a text string is returned (reply) and I determine wether the domain is available or not.

During the loop where I call the WhoIs servers, I add an item to a List of type domainInfo (below is a simplified version of the class):



The code for the List:



During the "WhoIs loop", I simply add an item the list:



Using LINQ, I can now join my SQL table (DomainPrices) with my in-memory collection (TLDs) and simply bind the result (domains) to a standard Repeater control:



That's it!! - It's that simple! .. I'm - far from it! - a LINQ expert, but the above example clearly show the benefits of being able to join SQL tables with in-memory collections (or what-ever you want to join!) - Just to be clear: I'm using LINQ to SQL to generate db.DomainPrices in the above example!

 

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed