I use the below mentioned query to Flatten an ObservableCollection:
using(RateDifferenceDBEntities db = new RateDifferenceDBEntities())
{
Items = new ObservableCollection<Item>(db.Items);
Orders = new ObservableCollection<ClaimDTO>(from order in db.Orders
from orderItemDetail in order.OrderItemDetails
from dispatch in order.Dispatches
from dispatchItemDetail in dispatch.DispatchItemDetails
where ((orderItemDetail.ItemId == dispatchItemDetail.ItemId && dispatchItemDetail.Rate > orderItemDetail.Rate)
&& (dispatch.DateOfDispatch >= StartDate && dispatch.DateOfDispatch <= EndDate))
select new ClaimDTO
{
SalesOrderId = order.SalesOrderId,
DateOfOrder = order.DateOfOrder,
PartyName = order.Party.PartyName,
------------> OrderItemName = Items.Where(x => x.ItemId == orderItemDetail.ItemId).FirstOrDefault().ItemName,
OrderQuantity = orderItemDetail.Quantity,
OrderRate = orderItemDetail.Rate,
OrderAmount = orderItemDetail.Amount,
SalesInvoiceId = dispatch.SalesInvoiceId,
DateOfDispatch = dispatch.DateOfDispatch,
------------> DispatchItemName = Items.Where(x => x.ItemId == dispatchItemDetail.ItemId).FirstOrDefault().ItemName,
DispatchQuantity = dispatchItemDetail.Quantity,
DispatchRate = dispatchItemDetail.Rate,
DispatchAmount = dispatchItemDetail.Amount
});
return Orders;
}
Can you see two dotted arrows in above code??
I geet an error there:
Unable to create a constant value of type 'Data.Item'. Only primitive types or enumeration types are supported in this context.
Here is the Heirarchical collection that I use to build the above mentioned query:
Order //Collection
|-OrderId
|-DateOfOrder
|-PartyName
|-OrderDetails //Collection
| |-ItemName
| |-Quantity
| |-Rate
| |-Amount
|-Dispatch //Collection
| |-InvoiceNo
| |-DateOfDispatch
| |-DispatchDetails //Collection
| | |-ItemName
| | |-Quantity
| | |-Rate
| | |-Amount