CAML is still the King over SPLinq

SharePoint 2007 was based on .NET 2.0, so when SharePoint 2010 came about, they just had to use some of the new developer goodness they had previously missed out on. Linq is incredibly cool, so they just had to implement a Linq provider for SharePoint. On the surface, it looks great. Who doesn’t like Intellisense? Who really likes to mess about with CAML?

They just forgot one thing; a fundamental fact in SharePoint is that the world our code operates in changes at the blink of an eye. This is a problem that Linq to SQL doesn’t face since the database schema doesn’t suddenly change.

If we take a look at a sample of the file generated by SPMetal.exe:

Can you spot the problem? I have several issues with this code.

Firstly, it’s using the display name to find the list. If a user happens to rename your list, you end up with this:

Secondly, it’s a specific language version being used. If you have to support multiple languages, you have a challenge.

If you don’t care two figs about multiple language, the first issue could have been solved by using the URL instead. Once created, that at least doesn’t change.

Ideally, the DataContext implementation should have some functionality to retrieve the localized strings from the site. One common scenario is to create a number of sites of a specific type where each site may be in a different language. If we could used the same DataContext agains all these sites, that would be helpful.

For the time being, I’ll stick with CAML. It may be nasty, but at least I can create code that adapts to the environment I’m running in.

CAML has left the building.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: