WCF 数据服务 (OData) 是否可以提供最大字符串长度元数据?
我正在使用 WCF 数据服务 (OData) 公开 SQL Server 数据库中的一些 varchar(10)
数据。 (我正在使用实体框架来公开它。)
有没有办法询问 OData 端点字符串可以有多长(即从 varchar(10)
获取 10)?
I am using WCF Data Services (OData) to expose some data that is a varchar(10)
in my SQL Server Database. (I am using entity framework to expose it.)
Is there a way to ask the OData endpoint how long a string can be (ie get the 10 from varchar(10)
)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果服务是基于 EF 的服务,并且 EF 模型的 CSDL 包含属性上的最大字符串长度属性,则服务的 $metadata 也将包含该属性。然后客户端可以解析 $metadata 并询问它。
请注意,WCF DS 客户端库没有执行此操作的 API。您可以使用 ODataLib 和 EdmLib 来读取 $metadata(或只是纯 XML)。它们位于最新 CTP 中的 Microsoft.Data.OData.dll 和 Microsoft.Data.Edm.dll 中 (http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data -services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx)。
但请注意,如果服务基于 EF 以外的其他内容,则当前无法以这种方式自定义 WCF DS 本身中的 $metadata 端点。您必须以其他方式自行公开 $metadata。
If the service is an EF based service, and your CSDL for the EF model contains the max string length attribute on the property, then the $metadata of the service will contain that attribute as well. The client can then parse the $metadata and ask for this.
Note that the WCF DS Client library doesn't have an API to do this though. You could use ODataLib and EdmLib to read the $metadata (or just plain XML). They are in Microsoft.Data.OData.dll and Microsoft.Data.Edm.dll in the latest CTP (http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data-services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx).
Note though, that if the service is based on something else than EF, then it's currently not possible to customize the $metadata endpoint in WCF DS itself this way. You would have to expose the $metadata yourself in some other way.