Может ли служба ODF WCF загружать связанные данные одним запросом? - PullRequest
0 голосов
/ 15 февраля 2012

У меня есть таблица с «Самостоятельными ссылками» - комментарий на одной стене может быть потомком другого. Это моя модель данных:

public class UserWall
{
    [Key]
    public int WId { get; set; }

    public Guid UserId { get; set; }

    public string WContent { get; set; }

    public Guid? WriterId { get; set; }

    [DataType(DataType.DateTime)]
    public DateTime WTime { get; set; }

    public int? ParentWId { get; set; }

    public virtual UserWall Parent { get; set; }

    public virtual ICollection<UserWall> Children { get; set; }
}

И вот, с этим URI / MyService.svc / UserWalls (1) / Я получил:

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://localhost:1636/CoreService.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
  <id>http://localhost:1636/CoreService.svc/UserWalls(1)</id>
  <category term="ESN.Models.UserWall" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <link rel="edit" title="UserWall" href="UserWalls(1)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="UserWalls(1)/Parent" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Children" type="application/atom+xml;type=feed" title="Children" href="UserWalls(1)/Children" />
  <title />
  <updated>2012-02-15T04:07:39Z</updated>
  <author>
    <name />
  </author>
  <content type="application/xml">
    <m:properties>
      <d:WId m:type="Edm.Int32">1</d:WId>
      <d:UserId m:type="Edm.Guid">e735311a-55fd-48cb-bac0-3441ae99ebea</d:UserId>
      <d:WContent>cức</d:WContent>
      <d:WriterId m:type="Edm.Guid">e735311a-55fd-48cb-bac0-3441ae99ebea</d:WriterId>
      <d:WTime m:type="Edm.DateTime">2012-02-15T01:01:00</d:WTime>
      <d:ParentWId m:type="Edm.Int32" m:null="true" />
    </m:properties>
  </content>
</entry>

И с помощью URI / MyService.svc / UserWalls (1) / Children я могу получить своих детей.

Но в любом случае, могу ли я загружать дочерние данные без дополнительного запроса?

1 Ответ

2 голосов
/ 15 февраля 2012

Да, вы должны использовать ключевое слово $ expand.Пример: /MyService.svc/UserWalls(1)?$expand=Children

...