NHibernate 3.0 QueryOver Syntax is the Bee's Knees

I’ll let a few queries from my current project say all that needs to be said.

public IEnumerable GetRolledUpEventsFor(DateTime tradeDate, IEnumerable tickers)
{
    return worker.On(connection, session =>
                                     {
                                         OrderEventRollup rollup = null;
                                         return session.QueryOver()
                                             .Where(x => x.TradeDate == tradeDate)
                                             .WhereRestrictionOn(x => x.Ticker).IsIn(tickers.ToArray())
                                             .Select(
                                                 list =>
                                                 list.SelectGroup(x => x.Ticker).WithAlias(() => rollup.Ticker)
                                                     .SelectSum(x => x.Shares).WithAlias(() => rollup.SharesTotal))
                                             .TransformUsing(Transformers.AliasToBean())
                                             .List();
                                     });
}
public IEnumerable GetBrokersByCode(IEnumerable brokerCodes)
{
    if (brokerCodes.Count() == 0) return Enumerable.Empty();
    return worker.On(connection, session =>
                                 session.Query()
                                     .Where(x => brokerCodes.Contains(x.Code))
                                     .ToList()
        );
}
public IEnumerable GetByTradeDateAndTicker(DateTime tradeDate, string ticker)
{
    return worker.On(connection, session =>
                                     {
                                         CSMSecurity security = null;
                                         return session.QueryOver()
                                             .Fetch(x => x.CSMSecurity).Eager
                                             .Fetch(x => x.TSOrderSecuritySpec).Eager
                                             .Fetch(x => x.CSMSecurity.CSMSecurityType).Eager
                                             .JoinAlias(x => x.CSMSecurity,() => security)
                                             .Where(x => x.TradeDate == tradeDate)
                                             .Where(() => security.Ticker == ticker)
                                             .List();
                                     });
}

So hawt indeed.

Follow me on Mastodon!