我正在使用DbContext和POCO實體實現WCF數據服務。WCF數據服務,展開問題
我目前正在公開兩個實體SalesOrder和Customer。
SalesOrder有一個名爲顧客財產,我應該能夠使用此查詢以檢索: http://localhost:902/ShopDataService.svc/SalesOrders()$展開;客戶
然而,沒有返回Customer對象。這是返回的每個條目(SalesOrder的)的XML塊...
<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>
你可以告訴它試圖返回Customer對象,因爲它正在發送元素,彷彿它沒有屬性,但它的配置與SalesOrder實體完全相同。
有沒有人碰到過這個問題? 編輯: 我公開這樣的數據(所以沒有權限問題)。
config.SetEntitySetAccessRule("SalesOrders", EntitySetRights.All);
config.SetEntitySetAccessRule("Customers", EntitySetRights.All);
config.SetEntitySetAccessRule("Addresses", EntitySetRights.All);
這意味着Customer屬性的值爲null。您是否確認過在您的數據庫中數據實際上存在? – 2011-03-17 15:20:28
@Vitek客戶不爲null。您可以在記錄中看到CustomerId。 – James 2011-03-17 15:28:12
CustomerID是外鍵,但EF也生成Customer導航屬性。有效載荷表示爲空,所以很可能該值爲空。你可以嘗試使用EF來訪問Customer屬性並查看它是否真的有價值嗎? (在使用EF生成的類的服務器上) – 2011-03-17 17:01:00