Dumping Master Child Objects

I have found LINQPad to be an amazing tool, and the Dump() methods is one of the most useful. However, I'm wondering if there's a way to dump an object that is a Master Child type of object. I have a collection of Header objects, and one of the properties of that Header object is a list of details.

public class PayrollHeader
{
public string u2_id { get; set; }
public int? PeoId { get; set; }
public int ClientId { get; set; }
public string EmployeeId { get; set; }
public string Department { get; set; }
public string EmployeeName { get; set; }
public string CheckNumber { get; set; }
public string VoucherNumber { get; set; }
public DateTime PayDate { get; set; }
public decimal GrossPay { get; set; }
public decimal NetPay { get; set; }
public decimal TotalDeductions { get; set; }
public decimal TotalTaxes { get; set; }
public decimal RetirementCatchUpAmount { get; set; }
public decimal RetirementLoanPayAmount { get; set; }
public decimal RetirementRothAmount { get; set; }
public decimal RetirementRothCatchUpAmount { get; set; }
public decimal RetirementSafe1 { get; set; }
public decimal RetirementSafe2 { get; set; }
public decimal TotalReportedTipAmount { get; set; }

public List Details { get; set; }

public PayrollHeader(string id)
{
u2_id = id;
Details = new List();
}
}

public class PayrollDetail
{
public string Type { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
}
So initially I have a List that I would like to dump to a Grid, and eventually export to a CSV file. I see the Dump() take a paraemter to define the depth, but I can't seem to get it to list the PayrollHeader properties AND the PayrollDetail objects contained within. Is there a way to automatically do this, or should I just write code to export it out how I want it, and not expect to actually see the results in LINQPad?

Comments

  • The following works for me:
    void Main()
    {
        var header = new PayrollHeader("test");
        header.Details.Add (new PayrollDetail ());
        header.Dump();
    }
    
    public class PayrollHeader
    {
        public string u2_id { get; set; }
        public int? PeoId { get; set; }
        public List<PayrollDetail> Details { get; set; }
    
        public PayrollHeader (string id)
        {
            u2_id = id;
            Details = new List<PayrollDetail>();
        }
    }
    
    public class PayrollDetail
    {
        public string Type { get; set; }
        public string Code { get; set; }
        public string Description { get; set; }
        public decimal Amount { get; set; }
    }
    The only change I've made is to change List to a generic List collection, so that it will compile.
  • That's actually what I have, the message stripped out the < and > signs, but it is a list already.

    I want to dump it to the DataGrid because it'll have way more than just 1000 records, and as such does not expand the child object in the DataGrid.

    What I really want to do is dump it into a CSV file. I tried the Util.ToCsvString on the object, but it only expands the Master object, and not the children. So am iterating through the Master object, then the children objects manually... It works for now, was just hoping it'd be a bit simpler because I writing this as a report for the Accounting folks, and was hoping they could just run it and view the results in the grid. But outputting it to a CSV file is probably better, don;t want to overwhelm their minds.

    My only issue now is it takes over an hour to run completely, and they have no way to run it for just themselves, they'll have to ask me to run it, wait an hour then put the resulting CSV file on the network somewehere since it's too big to email...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!