【发布时间】:2019-11-24 20:48:26
【问题描述】:
当我们在 Silverlight 应用程序中使用调用操作调用 WCF/WCF ria 服务时,它会返回正确的数据, 但是当我们以角度使用此服务或从邮递员调用它时,会返回 RootResults 之外的关系数据,并带有单独的“IncludedResults”。
服务/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();
}
实体框架元数据“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 响应,我做错了什么?请帮忙。
【问题讨论】:
标签: c# json wcf silverlight ria