public Billing[] getBilling(GetBillingRequest request) { DetachedCriteria criteria = DetachedCriteria.For <Bill>(); if (request.orderby != null) { RequestOrderByHelper.ConverToCriteria(request.orderby, orderbyFiledsMapping, criteria); } IList <Bill> billList = TheCriteriaMgr.FindAll <Bill>(criteria, request.beginRowIndex, request.beginRowIndex + request.rowSize); List <Billing> billingList = new List <Billing>(); foreach (Bill bill in billList) { Billing billing = fillBill(bill); foreach (BillDetail billDetail in bill.BillDetails) { BillingItem billingItem = fillBillDetail(billDetail); billing.AddBillingItem(billingItem); } billingList.Add(billing); } return(billingList.ToArray()); }