Say I have an OData query that looks like this (My actual query is much more complex):
Orders.Select(z => new { z.SubOrder.Addresses,
z.SubOrder.Cost,
z.SubOrder.SubOrderId,
z.Sequence});
This works fine. Except that the Address object has a sub object on it (StateRef). Since StateRef does a look-up on the State table, it is returned as null.
To illustrate, here is an example of how the address object Address might look:
Address:
string Street 1
string Street 2
StateRef PrimaryState
string City
// ... 42 other string attributes not shown ...
The StateRef
object has the name of the state on it, but also has some other important State properties (maybe state bird?)
So, what I am wondering is, do I have to now create a "sub projection" for z.SubOrder.Addresses that contains all 46 attributes just so that I can access the PrimaryState
item? (I Hope NOT)
Aside from being way more coding, it also means I have to use anonymous types. Which makes my mapping have to be by hand (instead of using AutoMapper).
So what I am looking for is a way to "Expand" the StateRef inside the projection?
Something like this:
Orders.Select(z => new { z.SubOrder.Addresses.Expand("PrimaryState"),
z.SubOrder.Cost, ^
z.SubOrder.SubOrderId, |
z.Sequence}); |
|
// This is not allowed by the compiler ----------+
Trying this give this error:
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Update: Here is an example query to illustrate what I am asking about:
Users.Take(10).Select(x=>new { x.Id, x.Reputation, x.Comments})
Run that against "data.stackexchange.com/stackoverflow/atom". You will see that Comments has a Post object that returns null.
I need that to return the values inside of it.
Note: I know I can manually type all of them out into a "sub" projection. Read above for why I do not want that.