Tuesday, March 25, 2008

Orlando Code Camp, Linq, and the DateTime Datatype

I spent last Saturday at the Orlando Code Camp and had a good time. I went to most of the Linq sessions. Since my co-worker, Rodd Harris, and I are in the process of developing a new application in C# and SQL Server, I felt like I needed to become more familiar with Linq. I really enjoyed Jim Wooley's sessions on Linq to XML and Building Data-Driven Web Sites Using Linq. Check out his web site at ThinqLinq.com, which is built using Linq.

I am mainly a SQL Server DBA/Developer, so I have some concerns about Linq To SQL regarding security, performance, and maintainability. Especially when I hear things like, "With Linq, you'll never have to write a stored procedure again." Well, I would beg to differ with that comment. Stored Procedures help isolate the database from people who think they know SQL and those who know how to use Access or ODBC to get to the data. Call me paranoid, but I think that some paranoia is necessary for a good DBA. I certainly believe Linq is a useful tool to have in your toolbox, but it should be used with thought as every tool should be. Toward the end of the day I had a good discussion about it with Andy Warren from End to End Training. He and I have similar feelings about Linq To SQL, but I think Andy is a little more anti-Linq To SQL than I am.

The coolest thing I learned about Linq was that it gives developers the ability to do heterogeneous joins. So I can have a Linq to Objects query and join on a Linq to SQL query. Now that is cool! For example this code creates an xml document using the new VB support for xml literals and then joins a Linq To XML query to a Linq To Objects query (taken from Jim Wooley's Linq To XML presentation):

Dim fileTypes = <FileTypes>
<FileType extension=".xml" description="Extensible Markup Language"/>
<FileType extension=".dtd" description="Data Type Definition"/>
<FileType extension=".htm" description="Hypertext Markup Language"/>
<FileType extension=".rtf" description="Rich Text Format"/>
<FileType extension=".txt" description="Text File"/>
<FileType extension=".wpd" description="WordPerfect Document"/>
</FileTypes>

Dim results = _
From fi In New System.IO.DirectoryInfo("C:\projects\linq\shakespeareXml").GetFiles _
Join ext In fileTypes. On fi.Extension.ToLower Equals ext.@extension _
Where fi.LastAccessTime >= Now.AddMonths(-6) _
Select FileName = fi.Name, Exten = ext.@description _
Order By FileName Descending

For Each item In results
Console.WriteLine(item)
Next


If you have the opportunity to go to these events and local user groups you should make the effort. It is worth it. You will always pick up something useful and it's a great opportunity to network.

I also found a cool blog post over at SQLSkills.com on why SQL Server's datetime data type starts at 1/1/1753, 1753, datetime and you.

No comments:

Post a Comment

So what do you think I am?