OData的查询不会扩大 [英] Odata query wont expand

查看:356
本文介绍了OData的查询不会扩大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用url像我的查询服务:

So I'm querying my service using a url like:

<一个href=\"http://a.com:3080/odata/DiscussionVM(6)\">http://a.com:3080/odata/DiscussionVM(6)?$expand=Section,User

http://a.com:3080/odata/DiscussionVM(6)?$expand=Section,User

在控制器的方法:

[EnableQuery(MaxExpansionDepth = 7)]
        public SingleResult<DiscussionVM> GetDiscussionVM([FromODataUri] int key)
        {
            return SingleResult.Create(db.DiscussionVMs.Where(discussionVM => discussionVM.DiscussionId == key));
        }

这工作并返回正确的JSON。

This works and returns the correct JSON.

不过,我再运行在不同的模式稍微更先进的查询:

However I then run the slightly more advanced query on a different model:

<一个href=\"http://a.com:3080/odata/OrganisationVM(30)?&\">http://a.com:3080/odata/OrganisationVM(30)?&$expand=Categories($expand=Discussions($expand=Section,User))

http://a.com:3080/odata/OrganisationVM(30)?&$expand=Categories($expand=Discussions($expand=Section,User))

和控制器动作:

// GET: odata/OrganisationVM(5)
        [EnableQuery(MaxExpansionDepth = 5, AllowedQueryOptions = AllowedQueryOptions.All)]
        public SingleResult<OrganisationVM> Get([FromODataUri] int key)
        {
            return SingleResult.Create(db.OrganisationVMs.Where(organisationVM => organisationVM.OrganisationId == key));
        }

这将返回下面的DiscussionVM JSON:

this returns the below DiscussionVM JSON:

{
@odata.type: "#Models.DiscussionVM",
DiscussionId: 6,
Section_SectionID: 1005,
User_Id: "4cecc52e-ac3a-4696-ac6c-175af2a6378a",
DateCreated: "2014-12-06T00:00:00Z",
OrgCat_OrganisationCategoryId: 1,
Text: "Dummy section",
Html: null,
IsUserCreated: true,
Organisation_OrganisationId: null,
Positives: null,
Negatives: null,
CommentCount: 1
}

但不包含用户部分对象。不会引发错误。正确的对象查询(异形)的数据库,并返回数据,包括用户和部分。

But contains no User or Section object. No error is thrown. The correct objects are queried (profiled) in the database and data including user and section are returned.

有什么想法?

感谢您的帮助。

推荐答案

从什么我和布拉德都聚集在这个苏答案,它可以是与实体类型混合复杂类型的问题。展开剧本非常好,如果你所有的类型都是实体,但如果混合两者,你最终会像你和我有怪异的行为。

From what Brad and I have gathered in this SO answer, it could be a matter of mixing complex types with entity types. Expand plays very well if all your types are entities, but if you mix both, you end up with weird behavior like you and I are having.

如果你将它们混合,展开级联已开始与实体类型和复杂类型结束。展开链似乎要结束了,而一个复杂类型都有一个实体类型属性。

If you do mix them, the expand cascade has to start with entity types and end with complex types. The expand chain seems to end where a complex type has an entity type property.

这可能来自哪里V3复杂类型指的是一个实体类型持平不支持。它是在V4中,但它是不完全干净的WebAPI如我们可以看到的。

This could come from v3 where a complex type referring to an entity type was flat not supported. It is in V4 but it is not totally clean with WebAPI as we can see.

由于缺乏对此事的文档和支持使得它索赔困难,这是绝对的真理,但至少它解释了我的情况,并提出我的东西的工作。希望它可以帮助你。

The lack of documentation and support on the matter makes it difficult to claim this is the absolute truth, but at least it explained my situation and made my stuff work. Hope it helps you too.

这篇关于OData的查询不会扩大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆