Massive

I finally had a good situation to use Massive, so I took it.

I was working on some functionality of a web service, and I needed to refactor some data access code. We were using SubSonic, and that is great and simple (typically), but this data access code is in a library, so changing meant opening up the project, making changes, building, pulling the new DLL over, etc. Not a huge amount of work, but too much work for a web service that is basically working with a single table.

There was minor learning curve, but Massive is pretty darned simple. It was mostly my mistakes in not paying attention, or old ASP classic-style blunders like using the wrong name for the column. Overall, it was a lot of fun.

My favorite bit was when I needed to get a SUM and a GROUP BY. If I were using EF or SubSonic, I may have struggled a bit with the proper LINQ syntax to do this (I need to increase my LINQ-FU skills, they are not strong), but with Massive I simply… wrote SQL… GASP!

I made a custom object with the 2 properties I needed, and then I looped over the returned values, pushed ’em into a list and returned it as an array. Here is the code:

[WebMethod, SoapHeader("Authorization")]
public DownloadDetail[] GetOrderDownloadCounts(object orderId, 
                                               object profileId) {
    var list = new List<DownloadDetail>();

    dynamic table = new DownloadAuthorization();
    object[] queryargs = { orderId, profileId };
    var auths = table.Query(@"SELECT Id, SUM(DownloadCount) AS Total
FROM Downloads
WHERE [email protected] AND [email protected]
GROUP BY Id", queryargs);
    foreach (dynamic auth in auths) {
        list.Add(new DownloadDetail { Id= auth.Id, 
                                      DownloadCount = auth.Total });
    }

    return list.ToArray();
}

I am thinking I could have done some sort of LINQ-y extension to eliminate the foreach loop, but maybe not? I don’t really know much (read: anything) about dynamic, so maybe it would not work? Not really sure. I guess I am showing my Intellisense crutch dependency here.
🙁