Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

IList you got me?

with 2 comments

As much as I hate to deal with numerical index I had to cross it one way or the other so be it.
Here is the fact, I am enjoy using Castle.ActiveRecord to wrap my DAL code cuz it simplify thing a lot for me > 80% somehow when it came to not so complex scenario like this one:

I want to allow my customer to list all the products and set the qty they want to order.
If they already order I would like to give them a chance to update qty for the product that they miss in the previous hit.

public IList LoadProductOrderList(int customer_id)
  IList result;

  ISession session = holder.CreateSession(typeof(AnnualTarget));
    // note: code wrapped for view
    string sql =  @"SELECT,, o.qty, as order_id
        FROM Products p JOIN Orders o
        ON = o.product_id  WHERE o.customer_id = :c1
        SELCT pid, name, 0 as qty, 0 order_id FROM Products";

    result = session.CreateSQLQuery(sql)
        .AddScalar("ID", NHibernateUtil.Int32)
        .AddScalar("NAME", NHibernateUtil.String)
        .AddScalar("QTY", NHibernateUtil.Int32)
        .AddScalar("ORDER_ID", NHibernateUtil.Int32)
        .SetInt32("c1", customer_id)

    } catch (Exception ex) {
    } finally {
    return result; // this is an IList ?!!! I don't like to work with it

As much as I hate, it is a bad idea to pass IList back to the caller object. What is interesting about this code session.CreateSQLQuery(sql) you can tell it to map the result to an Entity by call like this


But anyway I have got time to dig what AddEntity would do with the object pass in to me the road a head is a bit dark. Can I have something more simple?

The simple should be:

public IList LoadProductOrderList(int customer_id)
    IList betterResult = new List();
    for(int i = 0; i

Now it much better to work with

Written by Chorn Sokun

December 5, 2007 at 3:40 pm

Posted in Castle.ActiveRecord

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. […] Development by chornsokun on January 17th, 2008 This would be a continue part from my previous post, what I tried to do is find out how to use ActiveRecord “NHiberate to be clear” in my […]

  2. […] method to transform result into strong type; however its .List() method return an IList which doesn’t uncomforted me much because I addicted to generic & strong type […]

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: