Hello all, I'm working on a Ordering report, where an order can have no more than 5 items. So instead of displaying an Order row and 5 (or less) OrderItem rows below it, I want to combine them all into one row, so they looks something like this:
Order # | Name | Address | Item 1 | Item 1 Qty | Item 2 | Item 2 Qty .... ...
I've generated a Linq2SQL class, then create a new class to hold the combined Order & OrderItem, but somehow they keep displaying as multiple rows instead of 1 row, I'm not sure where it went wrong. Here's the code for the Report class:
public class Report
{
public int OrderId { get; set; }
public DateTime OrderDate { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public MyOrderItems Item1 { get; set; }
public MyOrderItems Item2 { get; set; }
public MyOrderItems Item3 { get; set; }
public MyOrderItems Item4 { get; set; }
public MyOrderItems Item5 { get; set; }
}
Here's the code for "MyOrderItems" class:
public class MyOrderItems
{
public string ProdName { get; set; }
public string ProdSku { get; set; }
public int ProdQuan { get; set; }
}
And here is my LINQ stuffs:
var report = (from O in dc.ac_Orders
join OI in dc.ac_OrderItems on O.OrderId equals OI.OrderId
join OS in dc.ac_OrderShipments on O.OrderId equals OS.OrderId
where OI.ProductId != null
select new Report
{
OrderId = O.OrderId,
OrderDate = O.OrderDate,
FirstName = OS.ShipToFirstName,
LastName = OS.ShipToLastName,
Company = OS.ShipToCompany,
Address1 = OS.ShipToAddress1,
Address2 = OS.ShipToAddress2,
City = OS.ShipToCity,
State = OS.ShipToProvince,
Zip = OS.ShipToPostalCode,
Item1 = new MyOrderItems { ProdName = OI.Name, ProdQuan = OI.Quantity, ProdSku = OI.Sku },
Item2 = new MyOrderItems { ProdName = OI.Name, ProdQuan = OI.Quantity, ProdSku = OI.Sku },
Item3 = new MyOrderItems { ProdName = OI.Name, ProdQuan = OI.Quantity, ProdSku = OI.Sku },
Item4 = new MyOrderItems { ProdName = OI.Name, ProdQuan = OI.Quantity, ProdSku = OI.Sku },
Item5 = new MyOrderItems { ProdName = OI.Name, ProdQuan = OI.Quantity, ProdSku = OI.Sku }
});
I currently have 1 order with 2 order items, but instead of displaying with just 1 row, it's displaying 2 rows with the exact same information except for the last 3 fields (ProdName, ProdQuan, and ProSku)
Any idea why? Thank you very much, Kenny.