As I mentioned in my last question, I reading through Alex D. James’ excellent three year old WCF Data Services Custom Provider blog. When I get to the section about related data we blindly describe all of our data as ResourceTypeKind.EntityType. I looked up the documentation, and there is no definition or guidance on using ResourceTypeKind.ComplexType.
I assume that it is a non-primitive type that is to always be included in my query, but cannot find anything that confirms that. This would be the model that is used for EF. I assume that is why this even exists.
If my assumption is correct, do I define my ComplexTypes in the same manner as I do my ResourceTypeKind.EntityTypes? Can I assume the same rules for WCF Data Services ComplexTypes as I do for EF ComplexTypes?
[Edit] What are the implications to querying across WCF Data Services a.k.a. OData? Am I expected to use .Expand(complex) a.k.a. $expand? In a client using LInQ and the WCF Data Service Client, should I be creating an anonymous type in order to fetch the complex type? Does the client know that they are ComplexType?
Complex types in OData are very similar to complex types in EF. By OData they are treated as atomic “value” types. So the response always includes the entire value (even if it is nested, that is contains multiple complex types in a hierarchy and so on).
As for query support, clients can address into the complex type only if they request a single value. (Assuming Address is a property on Customer which type is a complex type). So for example ~/Customers(1)/Address/City is a valid query and it returns just the City property of the Address complex value.
Since the value is treated as atomic, $expand doesn’t work on it (it will fail, as it only works on navigation properties). $select does work, but only on the entire complex property as a whole. So I can do ~/Customers?$select=Address which would return me all the customers but with only the Address property. I can’t do ~/Customers?$select=Address/City – that is invalid.
In a certain way you can view complex properties as “always expanded”, but it’s better to not think about them as entities/navigations, but as a separate thing.