LINQ to Everything

Charlie Calvert has a very valuable list of LINQ to <insert here> list

These are all LINQ implemented providers.

Quite a list!  LINQ has been something I’ve enjoyed working with.

I did learn recently on a side note that you can string together LINQ to SQL queries, that when get execute are treated as one query.


var cars = from p in dc.Cars where p.Model == "Focus";

var fordFocus = from c in cars where c.OwnerName = "Steve";

List<Cars> results = fordFocus.toList<Cars>();

This will create a joined sql query (ie. sql in statement) when executed as one query, not two separate database calls.

something like:

SELECT … FROM Cars WHERE ModelType IN (SELECT … FROM OwnerList WHERE OwnerId=Steve) 

Why is this? The query is not constructed until you attempt to enumerate through the results.  This is very key to understanding your queries in LINQ.

On a side note, I did have a need to force eager loading in LINQ to SQL.  The reason: by default it is set to lazyload.  But in my case, I wanted to get a master-detail loaded after I closed the DataContext.  If you attempt to lazyload after you have closed the DataContext, it won’t be able.

Code snippet:

using (FSDALDataContext dc = GetContext())
                DataLoadOptions loadOption = new DataLoadOptions();
                loadOption.LoadWith<Campaign>(cp => cp.TargetsDestroyeds);
                dc.LoadOptions = loadOption;

                Campaign campaign = dc.Campaigns.Single(c => c.CampaignId == campaignId);

                return campaign;

So, I’ve told it to go ahead and load the list of ‘targetsdestroyed’ when I retrieve a ‘campaign’.

(This is a one to many in my table structure)


Collection of Links

Or rather a ‘what have you been doing lately’?

As usual I’m exploring areas around IoC/DI containers, jQuery, and MS MVC.

I had a chance this weekend to plug in some MS MVC time and I’m happy with the results. This is the way that web apps should be built. No question in my mind. There is a reason that MVC has carried over the years. The ability to setup REST urls in the routing, controller first capability of wiring up objects to the view, and Html ‘helpers’ using the new .net extensions is too much to resist. The only issue I’ve run into so far is with REST urls and encoding/decoding. In my sample at home, I have a value of 4.JG53/Recon – the ‘slash’ here messes up the REST.

…/ShowPilots/4.JG53/Recon <- doesn’t work.

I tried encoding it to be 4.JG53%2Recon – but it takes that and decodes it back to the slash – oops. I’m investigating this one, outside of saying ‘don’t pass names like that’ 🙂

What I find interesting is that I used to struggle of ‘but webforms have these nice controls…’. enough of that garbage. Actually, they are rather over complicated to do simple things. The answer: javascript frameworks. Ext, jQuery, Yahoo, etc… all have rich javascript/CSS controls that do more than the .net controls. Take a tab control. Piece of cake with jQuery/Yahoo. No ‘atlastoolkit’ to fumbled around with. On top of that, browser support is always a key for these guys, they can’t publish javascript frameworks that only run on IE…. (MS…wake up!) 🙂

Lastly, back to IoC. My links today will show an example of how to build your own. Sure, it’s just a start, but it’s a good way to show the underpinnings of IoC. Microsoft P&P team released Unity in beta, it still has work to do in my opinion. The use of attributes for setter injection is just wrong to me. I don’t want to decorate my classes showing setter injection. To me, it shouldn’t be in my POCO classes. I’d rather wire them up in xml, than place that on my classes. Secondly, for the life of me I cannot find out how to set default values – ie. I pass in the connection string to my dao objects. I’ve used the container to store my connection string, setting it on the constructor. I cannot find this in Unity – maybe I’m missing something 🙂 So, when it came time to do the MS MVC, I ended up switching back to Castle’s Windsor. It’s just so rich and so easy at the same time that it’s too hard to resist.

Ok, on to the links:

Build Your Own Container – Part I
Build Your Own Container – Part II

MSContrib – very nice user community contributions including support for Windsor, Spring – new view engines, etc..

MS MVC – Design Philosophy
MS MVC Toolkit
Scott Guthrie’s 5 Part – how to’s (excellent starting place)
Part I – What is It?
Part II – Building an MVC Application
Part III – URL Routing
Part IV – Passing ViewData from Controllers to Views
Part V – Handling Form Edit and Post

Using JQuery with MS MVC

Just a simple example – but it shows how simple this is. So much better than dealing with the webforms leaky abstraction, id munging, complex postbacks, etc…



Some general links to the LINQ crowd:

1. LinqKit : “LINQKit is a free set of extensions for LINQ to SQL power users”

2. LINQ over NHibernate : Ayende has built a NHibernate Linq provider.

His project includes a comprehensive set of tests that run against Northwind database. A secondary benefit is he shows in his tests different linq queries as well 🙂

Unity Dependency Injection Container

The February CTP of the new Unity IOC has been released.


I need to play with this, but it could be a good alternative to Spring/Windsor. I’m glad to see the Enterprise P&P release this, as I hope it means more adoption by Microsoft shops to using Dependency Injection with a container.

David Hayden has a short but good blog post on using Unity with the MVC.NET

The official CodePlex site has a short writeup of Unity, as well as links to the download

Good stuff 🙂


Rob Conery has had his open source ORM/MVC code called ‘SubSonic’ around for awhile. I must say, the documentation, tools,etc… are excellent. He has released beta version 2.1. The new release has a nice ‘LINQ’ type query language (fluent interface style).

The latest tool is SubStage – which helps configure the ORM aspects of SubSonic. Tooling like this makes the job easier.

Read more here.