From NHibernate Sessions to Repository

Before:

using (ISession session = _sessionManager.OpenSession())

{

    IList list = session.CreateCriteria(typeof (State))

        .SetFirstResult(Settings.Default.LogsPageSize*currentPage)

        .SetMaxResults(Settings.Default.LogsPageSize)

        .Add(Expression.Eq("Connection.Id", interfaceId))

        .AddOrder(new Order("ArrivedAt", false))

        .List();

    return Util.ToArray<FileState>(list);

}

After:

return Repository<FileState>.FindAll(

    Settings.Default.LogsPageSize*currentPage,

    Settings.Default.LogsPageSize,

    Order.Asc("ArrivedAt"),

    Where.FileState.Connection.IdIs(interfaceId)

    );

Update: Changed new Order() to use clearer factory method.

Print | posted on Wednesday, August 09, 2006 9:39 PM

Feedback


Gravatar

#  8/9/2006 10:21 PM Oren Ellenbogen

To be honest, I'm not &quot;digging&quot; the API, but that's me. I prefer Steve's API, and even more - my API in SEE infrastructure but I am a &quot;little&quot; biased :).
In addition, I would advise you to replace the line new Order(&quot;ArrivedAt&quot;, false) and use some sort of Enum instead of the &quot;false&quot;. It will make the call a lot clearer.


Gravatar

#  8/9/2006 10:46 PM Ayende Rahien

I fixed the Order issue, you are correct, there is a nice overload that I should've called instead.

I'm not using the operator overloading yet mainly because that is in the new versions on NHibernate.


Gravatar

#  8/10/2006 1:59 PM Josh Robb

Is that a singleton I see before me?

Settings.Default

Mmmm... how do you test that?


Gravatar

#  8/10/2006 3:38 PM Ayende Rahien

I don't really test this particular issue.
It was either a singleton (in this case, the .Net 2.0 default settings) or a hard coded value.
Currently it translates to &quot;Windsor.config&quot;

If it is broken, everything else breaks as well

Comments have been closed on this topic.