OData 客户端未使用 $expand 进行补水

发布于 2024-10-26 14:35:26 字数 1193 浏览 7 评论 0原文

我使用 OData 一段时间了,发现它是设置服务器的绝佳工具。今天我遇到了一些我以前从未见过的东西,这让我感到非常困惑。

我在客户端上使用 .Expand 来请求获取报告时的数据树。我已经在原型中使用了精确的查询,并且效果非常好(即完全水合)。当我使用 Fiddler 发送查询时,响应数据包是完美的,并且包含我正在查找的所有数据。

问题在于,客户端尚未对任何扩展属性进行水合(服务引用与当前服务完全最新)。为了尝试弄清楚发生了什么,我将范围缩小到单个属性,但它仍然不起作用。

var report = (serviceContext.Reports.Expand("ReportAreas").Where(r=>r.ReportID==reportID)).SingleOrDefault();

给我报告,但 ReportAreas 包含 0 个项目。如果我随后尝试:

serviceContext.LoadProperty(report,"ReportAreas");

那么 ReportAreas 包含 20 个左右的项目。

这让我非常疯狂,因为 Expand 正在为不同的对象树(不同的查询但相同的功能代码)工作,没有任何问题。有人对我如何弄清楚这里到底发生了什么有建议吗???

更新:

今天关于此的一些新信息可能更奇怪,并向我暗示 OData 客户端中存在错误。我发现只有报表对象的子集会返回,而不会填充扩展属性。数据库中的大多数报告都非常好。即,如果我请求扩展了 ReportAreas 的所有报告(而不是细化为单个 reportID),则大约 80-90% 的 ReportAreas 计数为非零,其余部分为 0。

当返回的报告没有填充任何属性时(null或 0 计数)实际属性对象正在被实例化并且它们的属性正在被设置(从服务引用的 Reference.cs 文件中的断点),因此,例如属于 ReportArea 对象的 ReportID、PropertyAreaID 和 History 值被设置 16 次在查询解析期间,但在请求时 ReportAreas 列表的计数为 0。当我使用 _service.LoadProperty 时,它返回 16 个 ReportAreas。

在我看来,扩展查询中的引用不匹配,但它太一致了,不可能是一个简单的问题。有效的报告始终有效,无效的报告永远无效。真的希望有人能帮助我查明这一点,以便我可以继续进行一些有用的编码......

I've been using OData for a while now and am finding it a fantastic tool for setting up my server. Today I've come across something I haven't seen before and it's absolutely confounding me.

I'm using .Expand on the client to request a tree of data for a report when it's fetched. I've used the exact query in a prototype and it worked perfectly (ie fully hydrated). When I use Fiddler to send the query the response packet is perfect and includes all of the data I'm looking for.

The problem is that none of the expanded properties have been hydrated by the client (with a service reference completely up-to-date with the current service). In order to try and work out what's going on I've narrowed the scope right back to a single property and it's still not working.

var report = (serviceContext.Reports.Expand("ReportAreas").Where(r=>r.ReportID==reportID)).SingleOrDefault();

gives me the report but ReportAreas contains 0 items. If I then try:

serviceContext.LoadProperty(report,"ReportAreas");

then ReportAreas contains 20 or so items.

It's driving me absolutely crazy because Expand is working for a different object tree (different query but same functional code) without any issues at all. Does anyone have suggestions as to how I can work out what on earth is going on here???

Update:

Some new information on this one today which is possibly wierder and suggests to me a bug in the OData client. I've discovered that only a subset of the Report objects come back without the expanded properties being populated. MOST of the reports in the database are perfectly fine. ie If I request all Reports with ReportAreas expanded (instead of refining to a single reportID) about 80-90% have a non-zero count for ReportAreas where the remainder have 0.

When a report comes back without any of the properties populated (null or 0 count) the actual property objects are being instantiated AND their properties are being set (from breakpoints in the Reference.cs file for the service reference) so, for example the ReportID, PropertyAreaID and History values belonging to ReportArea objects are set 16 times during the query resolution but the ReportAreas list has a count of 0 when it is requested. When I use _service.LoadProperty it returns 16 ReportAreas.

It smells to me of a reference mismatch in the Expand query but it is too consistent to be a simple problem. Reports that work ALWAYS work and Reports that don't work NEVER work. Really hoping someone can help me pinpoint this so I can move on to some useful coding...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光倒影 2024-11-02 14:35:26

这个问题的解决方案(至少在我更好地理解之前)是设置

serviceContext.MergeOption = MergeOption.OverwriteChanges;

我被告知这与客户端不重新补充链接(如果它们已经被跟踪)有关。如果我发现更多/更好地理解问题,我会更新这个答案。

The solution to this problem (at least until I understand it better) is to set

serviceContext.MergeOption = MergeOption.OverwriteChanges;

I've been told this relates to the client not rehydrating links if they're already being tracked. I'll update this answer if I find out more/understand the problem better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文