WCF 数据服务 (OData) 是否可以提供最大字符串长度元数据?

发布于 12-18 10:57 字数 166 浏览 3 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(1

不离久伴2024-12-25 10:57:15

如果服务是基于 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.

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