Select * from [MonoRail].[Customers]

time to read 9 min | 1673 words

I just listened to the latest Hansleminutes, talking about MonoRail with Aaron and Jacob from Eleutian. Scott says that "Hansleminutes is the podcast that doesn't waste your time", but this is pushing it.  In about 20 minutes, they covered: (MonoRail, MonoRail views, Front Controller, Windsor Integration, Windsor, Testability, Mocking).

The most amusing thing about the guys from Eleutian is that they literally does stuff with code that is just out there. The part about cookies was new to the people who wrote the code, for instance. Particulary interesting to hear the questions that Scott asked (since I already knows the answers :-) ). One question that Scott asked and didn't get an answer was:

So if I am doing a Northwind database and I am go to the customer page and I want a grid with a bunch of customers. So in ASP.Net I go file>new page, Customers.aspx I drag a datagrid over, maybe a datasource. Select * from Customers bind to the datagrid and then I got a bunch of stuff in a grid.

The answer to Scott question is simple. You don't. You wouldn't do it in any real application anyway, and you wouldn't do it in MonoRail. You would have a data layer that doesn't include "select * from customers" in the UI, to start with.

Here is the really easy way to handle it:

  • Create a new class "CustomerControllers" in the Controllers directory. Inherit from Controller.
  • Add this method:

    public void Index()
    {
       PropertyBag["customers"] = Customer.FindAll();
    }

  • Create new directory under Views, called "Customers".
  • In this directory, create file "index.brail", in this file, put:

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head />

    <body>

           <h2>Customers grid</h2>

           <?brail

                  component GridComponentWithAutoGenerateColumns, {"source":customers}

           ?>    

    </body>

    </html>

  • Point your browser to:
    http://localhost/northwind/customers/index.rails
That is it.