2
votes

I am implementing WCF Data Services using a DbContext and POCO entities.

I am currently exposing two entities, SalesOrder and Customer.

SalesOrder has a property called Customer, which I should be able to retrive using this query: http://localhost:902/ShopDataService.svc/SalesOrders()?$expand=Customer

However, no Customer object is returned. This is the XML block for each entry (of SalesOrder) that is returned...

<entry>
<id>http://localhost:902/ShopDataService.svc/SalesOrders(60)</id>
<title type="text"></title>
<updated>2011-03-17T14:58:11Z</updated>
<author>
  <name />
</author>
<link rel="edit" title="SalesOrder" href="SalesOrders(60)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ShippingAddress" type="application/atom+xml;type=entry" title="ShippingAddress" href="SalesOrders(60)/ShippingAddress" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/InvoiceAddress" type="application/atom+xml;type=entry" title="InvoiceAddress" href="SalesOrders(60)/InvoiceAddress" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer" type="application/atom+xml;type=entry" title="Customer" href="SalesOrders(60)/Customer">
  <m:inline />
</link>
<category term="CarterShop.Commerce.Entities.SalesOrder" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
  <m:properties>
    <d:Id m:type="Edm.Int32">60</d:Id>
    <d:Created m:type="Edm.DateTime">2011-03-12T15:23:47.07</d:Created>
    <d:ItemCost m:type="Edm.Decimal">8.00</d:ItemCost>
    <d:ShippingCost m:type="Edm.Decimal">0.00</d:ShippingCost>
    <d:ShippingVat m:type="Edm.Decimal">0.00</d:ShippingVat>
    <d:ItemVat m:type="Edm.Decimal">1.60</d:ItemVat>
    <d:Total m:type="Edm.Decimal">9.60</d:Total>
    <d:ShippingAddressId m:type="Edm.Int32" m:null="true" />
    <d:InvoiceAddressId m:type="Edm.Int32" m:null="true" />
    <d:Paid m:type="Edm.DateTime" m:null="true" />
    <d:Shipped m:type="Edm.DateTime" m:null="true" />
    <d:TransactionId m:null="true" />
    <d:OrderNumber>000068</d:OrderNumber>
    <d:SalesOrderStageId m:type="Edm.Int32">2</d:SalesOrderStageId>
    <d:CustomerId m:type="Edm.Int32">2</d:CustomerId>
    <d:CancellationReasonId m:type="Edm.Int32" m:null="true" />
    <d:ShippingBracketId m:type="Edm.Int32" m:null="true" />
  </m:properties>
</content>

You can tell it is trying to return the Customer object, because it is sending that element, as if it has no properties, but it is configured exactly the same as the SalesOrder entity.

Has anyone hit this issue before? Edit: I am exposing the data like this (so no permissions problems).

config.SetEntitySetAccessRule("SalesOrders", EntitySetRights.All);
config.SetEntitySetAccessRule("Customers", EntitySetRights.All);
config.SetEntitySetAccessRule("Addresses", EntitySetRights.All);
1
This means the value of the Customer property is null. Did you verify that in your DB the data is actually there? - Vitek Karas MSFT
@Vitek The Customer is not null. You can see the CustomerId in the record. - James
The CustomerID is the foreign key, but EF also generates a Customer navigation property. And the payload represents that as null, so it's very likely that the value is null. Could you try using just EF to access the Customer property and see if it actually has a value? (on the server using the EF generated classes) - Vitek Karas MSFT
Vitek, the customer will always be null until its asked for.. which is what I assume the WCF Data Services should do (basically execute .Include() on the query). I have been using the Entity Framework with normal WCF services building the application. I want to use DataServices for Silverlight, but I thought it should just work? If I have to write custom methods with Include's in I may as well use normal WCF Services? - James
WCF Data Services definitely does the Include, you don't need to write it yourself. In short, I can't see anything wrong with the code you posted and if you say the data is in fact there, I really don't know what's wrong. - Vitek Karas MSFT

1 Answers

1
votes

This is not properly supported in Data Services. As usual - when you need something apart from Hello-World, you must write proper applications, rather than try to use 'magic' solutions such as Data Services.