【发布时间】:2013-10-30 06:01:18
【问题描述】:
当使用 DataServiceContext 类的实例从一个 odata 端点具体化对象时,该端点公开了一些 custom annotations,如何获取注释数据。我看不到任何明显的扩展点。
【问题讨论】:
标签: asp.net-web-api odata wcf-data-services
当使用 DataServiceContext 类的实例从一个 odata 端点具体化对象时,该端点公开了一些 custom annotations,如何获取注释数据。我看不到任何明显的扩展点。
【问题讨论】:
标签: asp.net-web-api odata wcf-data-services
自定义注释不会作为 DataServiceContext 上的一流概念公开,但您可以通过挂钩到客户端响应处理管道来访问它们。此代码将在每个实体读取完毕后运行:
context.Configurations.ResponsePipeline.OnEntryEnded(
entryArgs => DoSomething(entryArgs.Entry.InstanceAnnotations));
在内部,WCF 数据服务客户端使用称为 ODataLib(NuGet 上的 Microsoft.Data.OData)的较低级别的库。响应和请求管道允许您在需要时深入到较低级别以获取额外信息,但您仍然可以获得使用成熟的 WCF 数据服务客户端库的所有便利。您在处理管道上使用的 ODataEntry、ODataFeed 等类都是 ODataLib API 的一部分。
【讨论】: