本文介绍了如何解决在OData Url中使用复合标识密钥的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体OrderItem ,其中包含 OrderId ProductId 整数字段,这两个字段构成了 identity key / primary key 此表。

我想使用 OData / Web API 通过服务公开此类实体,并能够选择 OrderItem 实例通过它们复合ID

I have an entity OrderItem that has OrderId and ProductId integer fields and these two fields form the identity key/primary key for this table.
I would like to use OData/Web API to expose such entities through a service and to be able to select OrderItem instances by they composite ID.

URL 应该是什么格式?

是否存在处理此类情况的最佳实践?

Are there any best practices for handling such scenarios?

推荐答案

URL中的复合键使用如下语法:

Composite keys in the URL use syntax like this:

~/OrderItems(OrderId=1234,ProductId=1234)

语法在(请参见 compoundKey的定义)

The "grammar" is defined in the OData ABNF Construction Rules (see the definition for "compoundKey")

在OASIS中可以找到示例用法'

An example usage can be found in OASIS' OData Version 4.0. Part 2: URL Conventions Plus Errata 03

请注意,复合键(又称复合键谓词)已经出现在。

Note that the "composite key" (aka "complex key predicate") has been around since OData 1.0.

这篇关于如何解决在OData Url中使用复合标识密钥的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:36