"IncludedResults" 中的 WCF/WCF Ria 服务 returns 关系数据

WCF / WCF Ria Service returns relational data in "IncludedResults"

WCF/WCF ria 服务 return 当我们使用调用操作在 silverlight 应用程序中调用它时的正确数据, 但是当我们在 angular 中使用此服务或从 RootResults 之外的邮递员 return 的关系数据中调用它时,使用单独的 "IncludedResults".

Service/API 方法 -

public IQueryable<viewauthor> getauthors(int author_id)
        {
            IQueryable<viewauthor> lstAuthor = null;
            lstAuthor = this.ObjectContext.books.Include("books").Where(p => p.author_id == author_id).AsQueryable();
            IEnumerable<viewauthor> lstResult = lstAuthor.ToList().Trim();
            return lstResult.AsQueryable();
        }

Entity framework 元数据 "author.metada.cs" -

[MetadataTypeAttribute(typeof(ViewAuthor.ViewAuthorMetadata))]
    public partial class ViewAuthor
    {
    public string AUTOR_ID { get; set; }
    ....
    ....

    [Include]
    public EntityCollection<books> Books { get; set; }
    ....
    ....
    }

来自 "getauthors" API -

的实际 JSON 响应
{
  "SelectDocDetailsByMattterIDResult": {
    "TotalCount": 1,
    "IncludedResults": [
      {
        "__type": "books:#library.Web.Data",
        "book_id": 1,
        "title": "Test book 1"
      },
      {
        "__type": "books:#library.Web.Data",
        "book_id": 2,
        "title": "Test book 2"
      },

    ],
    "RootResults": [
      {
        "author_id": 1,
        "ADD_TIME": "\/Date(1559300437353+0530)\/",
        "name": "test author"
      }
    ]
  }
}

预期 JSON -

{
  "SelectDocDetailsByMattterIDResult": {
    "TotalCount": 1,
    "RootResults": [
      {
        "author_id": 1,
        "ADD_TIME": "\/Date(1559300437353+0530)\/",
        "name": "test author",
        "books": [
          {
            "__type": "books:#library.Web.Data",
            "book_id": 1,
            "title": "Test book 1"
          },
          {
            "__type": "books:#library.Web.Data",
            "book_id": 2,
            "title": "Test book 2"
          },

        ]
      }
    ]
  }
}

我需要与 SilverLight 应用程序相同的 JSON 响应,我做错了什么?请帮忙。

您是如何定义服务接口的,服务器使用了哪个绑定?请参考我的定义

        [OperationContract]
        [WebInvoke(ResponseFormat =WebMessageFormat.Json,RequestFormat =WebMessageFormat.Json)]
        List<Product> SayHello();

    public class Product
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public List<Animal> Animals { get; set; }


    }
    public class Animal
    {
        public int ID { get; set; }
        public string Name { get; set; }

}

结果。

此外,默认的序列化器是XMLSerializer,我们可以使用DataContractSerializer来简化序列化,请参考下面link.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-contract-known-types
如果有什么我可以帮忙的,请随时告诉我。