WCF数据服务,扩展问题
我正在使用DbContext和POCO实体实现WCF数据服务 我目前公开了两个实体,SalesOrder和Customer SalesOrder有一个名为Customer的属性,我应该能够使用以下查询检索该属性: ()?$expand=客户 但是,不会返回任何客户对象。这是返回的每个条目(SalesOrder)的XML块WCF数据服务,扩展问题,wcf,entity-framework,wcf-data-services,Wcf,Entity Framework,Wcf Data Services,我正在使用DbContext和POCO实体实现WCF数据服务 我目前公开了两个实体,SalesOrder和Customer SalesOrder有一个名为Customer的属性,我应该能够使用以下查询检索该属性: ()?$expand=客户 但是,不会返回任何客户对象。这是返回的每个条目(SalesOrder)的XML块 <entry> <id>http://localhost:902/ShopDataService.svc/SalesOrders(60)</id&
<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>
这在数据服务中不受适当支持。与往常一样-当您需要Hello World之外的内容时,您必须编写适当的应用程序,而不是尝试使用数据服务等“神奇”解决方案。这意味着Customer属性的值为空。您是否验证了数据库中的数据是否确实存在?@Vitek客户不为空。您可以在记录中看到CustomerId。CustomerId是外键,但EF还生成客户导航属性。有效载荷表示为null,因此很可能值为null。您是否可以尝试使用just EF访问Customer属性,看看它是否真的有值?(在使用EF生成的类的服务器上)Vitek,客户将始终为空,直到其被请求。。这就是我假设WCF数据服务应该做的(基本上是在查询上执行.Include()。我一直在使用实体框架和普通的WCF服务构建应用程序。我想为Silverlight使用DataServices,但我认为它应该可以工作?如果我必须在中使用Include编写自定义方法,我还可以使用普通的WCF服务?WCF数据服务肯定包含这些方法,您不需要自己编写。简言之,我看不出你发布的代码有任何错误,如果你说数据确实在那里,我真的不知道哪里出了问题。使用LoadProperty似乎适合我。扩展被破坏:(
config.SetEntitySetAccessRule("SalesOrders", EntitySetRights.All);
config.SetEntitySetAccessRule("Customers", EntitySetRights.All);
config.SetEntitySetAccessRule("Addresses", EntitySetRights.All);