开放式实体上属性的合法字符 [英] Legal characters for properties on an open-type entity

查看:72
本文介绍了开放式实体上属性的合法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了 WCD 数据服务/OData 服务器,并将实体设置为开放类型.我正在使用自定义 IMetadataProvider、IQueryProvider 等.我可以创建我的实体、设置打开的属性、检索它们、更新和搜索——主要是.当我尝试搜索名称中带有破折号"之类的属性时,问题就出现了

I have implemented a WCD Data Services / OData server, with an entity set as an open type. I am using custom IMetadataProvider, IQueryProvider, etc. I can create my entity, set open properties, retrieve them, update, and search -- mostly. The problem comes when I attempt to search for a property with something like a "dash" in the name

这有效:

GET /Service/Cases?$filter=ABC eq 'ABC'

这不起作用:

GET /Service/Cases?$filter=A-BC eq 'ABC'

这也不起作用:

GET /Service/Cases?$filter=A%2DBC eq 'ABC'

我收到以下错误:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code />
  <message xml:lang="en-US">Syntax error at position 7.</message>
</error>

(正如我所说,我能够获得一个实体,其名称中带有一个破折号的开放属性.并对其进行更新等)

(And as I said, I am able to get an entity with an open property with a dash in the name. And update it, etc.)

我猜想解析 URL 的任何东西都将破折号解释为减法表达式,这是有道理的.除了如果我正确阅读 OData 规范,实体的属性名称由 entitySimpleProperty 定义(未在规范中定义,但我认为是 entityProperty 的拼写错误)...定义为 *pchar,如定义RFC 3986 第 3.3 节.反过来,评估为...

I would guess that whatever is parsing the URL is interpreting the dash as a subtraction expression, which makes sense. Except that if I read the OData spec correctly, an entity's property name is defined by entitySimpleProperty (which isn't defined in the spec, but I presume is a typo for entityProperty)... which is defined as *pchar, as defined in RFC 3986 section 3.3. That, in turn, evaluates to...

pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

其中 ALPHA 是 %41-%5A 和 %61-%7A,DIGIT 是 %30-%39,连字符是 %2D,句点是 %2E,下划线是 %5F,波浪号是 %7E.

Where ALPHA is %41-%5A and %61-%7A, DIGIT is %30-%39, hyphen is %2D, period is %2E, underscore is %5F, and tilde is %7E.

这表明破折号是一个合法字符,完整循环.不是我需要它.那么,规范的哪一部分规定了允许的字符是什么?

And that shows that a dash is a legal character, coming full circle. Not that I need it to be. So, what part of the spec dictates what the allowable characters are?

感谢您的帮助!

推荐答案

属性必须按照 CSDL (EDM) 规则有效.这允许任何有效的标识符,例如由这段 XSD 定义的:

A property must be valid as per CSDL (EDM) rules. That allows any valid identifier as defined for example by this piece of XSD:

  <xs:simpleType name="TSimpleIdentifier">
    <xs:restriction base="xs:string">
      <xs:maxLength value="480" />
      <!-- The below pattern represents the allowed identifiers in ECMA specification -->
      <xs:pattern value="[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}" />
    </xs:restriction>
  </xs:simpleType>

它基本上是任何有效的编程语言标识符.不幸的是,OData 规范在这方面可能有点混乱(甚至可能是错误的).

It's basically any valid programming language identifier. The OData spec might be a bit confusing (or maybe even wrong) on this unfortunately.

请注意,WCF DS 在大多数情况下不会对此进行验证,因为验证检查的成本太高了.它依赖于 IDataServiceMetadataProvider 实现来做正确的事情.这就是为什么您看到它在某些情况下有效,而在某些情况下无效.

Note that WCF DS doesn't validate this in most cases since the validation check would be way too expensive. It relies on the IDataServiceMetadataProvider implementation to do the right thing. That's why you see it working in some cases and in some it doesn't.

这篇关于开放式实体上属性的合法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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