I Am Not Myself

Bills.Pay(Developer.Skills).ShouldBeTrue()

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: