none
selecting inner object collection RRS feed

  • Question

  • Domain: purchase order

    I have an Order and OrderLine table/Object[i have set forgine key (FK) relationshipt like OrderLine have a FK OrderId]

    As you expect   a single order may have one or more OrderLine.

    As both of them have more than 25 properties I just took few form them and created an objects

    MiniOrder and MiniOrderLine

    Now

    Class MiniOrder{

    Int Id;

    String orderDescription;

    IList< MiniOrderLine>  lineList;

    }

    Class MiniOrderLine{

    Int oderlineId;

    String  description;

    }

    Now from Order and OrderLine table how can I fetch  a MiniOrder ooject having id=20

    Tuesday, May 11, 2010 5:12 PM

Answers

  • public List<MiniOrder> ConvertToMiniOrders(List<Order> orders)
    {
       return (from order in orders 
          select new MiniOrder 
          { 
          Id = order.Id, 
          Description = order.Description, 
          Lines = (from line in order.Lines
             select new MiniOrderLine
             {
             LineId = line.LineId,
             Description = line.Description
             }).ToList()
          }).ToList();
    }
    

    donno why you would want to do this, but this is a solution.  FYI, you can delayed load properties on Sql To Linq objects, and you usually define which collums to display in most gridviews.

    • Marked as answer by sujithu Thursday, May 13, 2010 4:39 AM
    Wednesday, May 12, 2010 6:33 PM

All replies

  • public List<MiniOrder> ConvertToMiniOrders(List<Order> orders)
    {
       return (from order in orders 
          select new MiniOrder 
          { 
          Id = order.Id, 
          Description = order.Description, 
          Lines = (from line in order.Lines
             select new MiniOrderLine
             {
             LineId = line.LineId,
             Description = line.Description
             }).ToList()
          }).ToList();
    }
    

    donno why you would want to do this, but this is a solution.  FYI, you can delayed load properties on Sql To Linq objects, and you usually define which collums to display in most gridviews.

    • Marked as answer by sujithu Thursday, May 13, 2010 4:39 AM
    Wednesday, May 12, 2010 6:33 PM
  • Great answer
    Thursday, May 13, 2010 4:39 AM