如何从WCF数据服务Webget返回实体框架实体?

时间:2010-11-12 19:45:57

标签: entity-framework entity wcf-data-services

我正在尝试通过我的WCF数据服务中的WebGet操作返回一个简单的对象(使用EF 4在EDMX中创建)。我能够看到对象,但是没有填充作为对象的属性(在这个Case DisplaySize是空的,即使我已经设置了它。我打算进行数据库调用以从非填充这个-EF生成表,因为我们还没有将所有数据迁移到新模式。(请从中推断出对象类型)

[WebGet]
    [SingleResultAttribute]
    public Display GetDisplay(int displayId)
    {
        Display foundDisplay = new Display();           
        foundDisplay.DisplaySize = new DisplaySize() { Id = 1, Width = 1024, Height = 768, Dimensions = "1024 X 768" };
        foundDisplay.Id = displayId;
        return foundDisplay;
    }

我正在使用的网址:http://localhost:1354/services/EDMDataService.svc/GetDisplay?displayId=1 来自呼叫的xml是:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="http://localhost:1354/services/EDMDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <id>http://localhost:1354/services/EDMDataService.svc/Displays(1)</id>
  <title type="text"></title>
  <updated>2010-11-12T19:34:29Z</updated>
  <author>
    <name />
  </author>
  <link rel="edit" title="Display" href="Displays(1)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/DisplaySize" type="application/atom+xml;type=entry" title="DisplaySize" href="Displays(1)/DisplaySize" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Address" type="application/atom+xml;type=entry" title="Address" href="Displays(1)/Address" />
  <category term="DataModels.Display" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:DisplaySizeID m:type="Edm.Int32">0</d:DisplaySizeID>
      <d:DisplayTypeID m:type="Edm.Int32">0</d:DisplayTypeID>
      <d:TimeZoneID m:type="Edm.Int32" m:null="true" />
      <d:Facing m:null="true" />
      <d:PanelNumber m:type="Edm.Int32" m:null="true" />
      <d:DisplayTemplateTypeID m:type="Edm.Int32">1</d:DisplayTemplateTypeID>
      <d:DisplayGUID m:null="true" />
      <d:RegistrationKey m:null="true" />
      <d:FirmwareVersion m:null="true" />
      <d:Id m:type="Edm.Int32">1</d:Id>
      <d:Base m:type="DataModels.Base">
        <d:Title>test</d:Title>
        <d:Summary>Description would go here</d:Summary>
        <d:DataCenterSiteID m:type="Edm.Int32">0</d:DataCenterSiteID>
      </d:Base>
    </m:properties>
  </content>
</entry>

1 个答案:

答案 0 :(得分:0)

只需在您的网址中添加&amp; $ expand = DisplaySize,响应也会包含展开的实体。

相关问题