2011-03-17 57 views
2

我正在使用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); 
+0

这意味着Customer属性的值为null。您是否确认过在您的数据库中数据实际上存在? – 2011-03-17 15:20:28

+0

@Vitek客户不为null。您可以在记录中看到CustomerId。 – James 2011-03-17 15:28:12

+0

CustomerID是外键,但EF也生成Customer导航属性。有效载荷表示为空,所以很可能该值为空。你可以尝试使用EF来访问Customer属性并查看它是否真的有价值吗? (在使用EF生成的类的服务器上) – 2011-03-17 17:01:00

回答

1

这在数据服务中没有得到适当的支持。像往常一样 - 当你需要除了Hello-World以外的东西时,你必须编写适当的应用程序,而不是尝试使用'神奇'的解决方案,如数据服务。

+0

反而使用LoadProperty似乎适用于我。展开已损坏:( – Kelly 2012-04-13 16:26:46