ODATA EXPAND 无法正常工作
我有一个网址过滤器,例如:t1?$filter=ID eq 1&$expand=t2/t3/t4/t5/t6。
现在,当我使用上下文作为第一个查询运行此查询时,我得到了一切!当我从另一页运行相同的查询并且这是使用相同对象上下文的上一个查询之后运行的第二个查询时,查询在 t3 处停止扩展!即使对象 id 明显存在,该对象仍为 null。数据存在!所以这里有一些非常奇怪的事情。注意:我使用的是单例对象上下文工厂类,因此每个页面都会实例化自己的对象上下文以用于执行 CRUD 操作。
I have a url filter like: t1?$filter=ID eq 1&$expand=t2/t3/t4/t5/t6.
Now when I run this query as the very first query using the context, I get everything! When I run this same one from another page and it is the second query run after a previous one using the same objectcontext, then the query stops expanding at t3! The object is null even though the objects id is clearly there. The data exists! So there is something really odd here. Note: I am using a singleton objectcontext factory class, so each page instantiates its own object context to use to execute CRUD operations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是 WCF DS 客户端库(DataServiceContext 和相关类),那么这很可能是由于客户端上的 DataServiceContext.MergeOption 设置造成的。默认值为 AppendOnly,这意味着如果客户端上已存在给定实体的实例,则来自服务器的新数据将不会更新它(这是为了防止查询覆盖客户端上可能进行的更改)。您可以将 MergeOption 更改为 OverwriteChanges,然后将使用服务器值。 (它甚至适用于导航属性,这就是为什么展开似乎不起作用,但实际上服务器确实将数据发送回客户端,但客户端将其丢弃)。
Assuming you're using WCF DS Client library (DataServiceContext and related classes), then this is very likely due to DataServiceContext.MergeOption setting on the client. The default is AppendOnly which means that if an instance of the given entity already exists on the client, the new data comming from the server will not update it (this is to prevent queries overriding possible changes made on the client). You can change the MergeOption to OverwriteChanges and then the server values will be used. (It applies even to navigation properties, that's why the expand doesn't seem to work, but in reality the server does send the data back to the client, but the client drops it).