I would like/need to flatten my object heirarchy for databinding. I'd like to see about binding to an IQueryable supported grid like DevExpress's. Really I only need the IQueryable implementation for my CustomerName and OrderDate fields (that is, I only need on demand querying based on these fields). I've tried every implementation I can think of to make this work.
From reading elsewhere, I understand that we cannot have grouping clauses such that a group by date can only consist of that DateTime field alone. (ie. group item by new {item.Name, item.Date } into grouping is a no go).
Additionally, the correlation requirements have made this a bit more difficult. I cannot figure out a way of doing the following effectively:
var result=
from o in metaData.Order
select new {
Date=o.Date
Addresses=o.Customer.Addresses (throws an error....)
The closest I've gotten to a working query (I guess) is:
var datasource = (
from order in metaData.Order
group order by order.Date into outerGrouping
from g in outerGrouping
where g != null
group g by g.CustomerID into innerGrouping
where innerGrouping != null
select new {
Name=new CustomerEntity(innerGrouping.Key.CustomerID).Name
}
the above throws a null reference exception...
Ideally, what I really want is this:
var datasouce=
from order in metaData.Order
group order by new {order.Date, order.Customer} into grouping // won't work (no grouping on entites, no multiple group expressions with DateTimes)
select new {
CustomerName=grouping.Key.Customer.Name // won't work because of above and correlation constrains
Addresses=grouping.Select(order=>order.Customer.Addresses) //won't work because of correlation
Date=order.Date
}
Note that an acceptable solution would be to use in memory projections for everything except the Date and Name fields (if it makes any difference):
var datasource=
from order in metaData.Order
select new {
Addresses=order.Customer.Addresses.ToList() // doesn't work either, even though I just want to force the expansion to IEnumerable
}
Is anything like this possible?