1

拥有来自 ADO.NET 实体数据模型的 WCF 数据服务

三张桌子

docSVsys: PK ID 
          ,sValue


docSVtext: composite PK sID, fieldID 
           ,mValue

        sID has FK relation to docSVsys,ID
        fieldID has FK Relation to docFieldDef.ID

docFieldDef PK, ID
            ,fName

docFieldDef 是一个小型半静态表,将 fieldID 与字段名称相关联

可以从 PK 扩展到 FK - 这行得通

  http://localhost:64638/WcfDataService1.svc/docSVsys(1)?$expand=docSVtext 

无法从此 FK 扩展到 PK - 这失败了。我可以做这个工作吗?

  http://localhost:64638/WcfDataService1.svc/docSVtext?$top=1&$expand=docFieldDef 

SO 不是为了评论,而是。ODATA 和 EF 是很好的工具。这只是很多没有映射到自动化模型中的数据。我只是添加了一些特定的 WCF 服务,而不是实现 ODATA。

未能成功拦截 .NET 代码中的 TSQL,但能够使用 SSMS Profiler 捕获 TSQL。这是一个有效(但格式错误)的查询超时。它从一个有 330 万条记录的表连接到一个有 100 条记录的表,然后处理前 1 条记录。在 330 万条表上,连接是复合键的第二个 int。连接甚至不是直接的 - 连接是通过子查询。重构为直接连接和仍然很长的查询 (2:30)。排序顺序是 PK 的第二个组成部分,然后是第一个(较大的表)。将排序顺序更改为第一个组件,第二个组件,查询变为 0(瞬时)。两个排序顺序仍然具有相同的查询计划。这也是一个带有 UI 的应用程序,任何查询都不会超过 1 秒,但都是手工制作的 TSQL。

想要一个 ODATA 接口,但既需要限制查询类型,又需要手工制作 TSQL。可以走自定义数据服务提供者的路径并实现 iQueryable 但这非常困难并且不能解决限制查询类型的第一个问题(不允许愚蠢的查询)。有没有办法兼容 ODATA 但限制查询类型(并制作 TSQL)。此应用程序的 ODATA 的目的是根据一些非常简单的标准导出大量数据。

有趣的是这个作品

  http://localhost:64638/WcfDataService1.svc/docSVtext(fieldID=101,sID=1)?$expand=docFieldDef

这有效(FK 回到 PK)

  http://localhost:64638/WcfDataService1.svc/docSVtext?$top=1&$expand=docSVsys
  (this may be a config issue - will review the keys - keys relationships look in order)
  The only difference I see it that is where it walks the name of the key was the same  in the two tables and where it failed the name of the key changed.

这可行,但按此顺序查看此数据没有价值

  http://localhost:64638/WcfDataService1.svc/docFieldDef?$top=1&$expand=docSVtext

失败的提琴手

> # Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
> 6 500 HTTP    localhost:64638 /WcfDataService1.svc/docSVtext?$top=1&$expand=docFieldDef   250 no-cache
>   application/xml iexplore:3188            GET
> /WcfDataService1.svc/docSVtext?$top=1&$expand=docFieldDef HTTP/1.1
> Accept: text/html, application/xhtml+xml, */* Accept-Language: en-us
> User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;
> Trident/5.0) Accept-Encoding: gzip, deflate Connection: Keep-Alive
> Host: localhost:64638 Cookie:
> ASP.NET_SessionId=l1qpumn5xuopnsyapavocw3a
> 
> 
> HTTP/1.1 500 Internal Server Error Server: ASP.NET Development
> Server/10.0.0.0 Date: Thu, 28 Jun 2012 23:03:32 GMT X-AspNet-Version:
> 4.0.30319 DataServiceVersion: 1.0; Content-Length: 250 Cache-Control: no-cache Content-Type: application/xml Connection: Close
> 
> <?xml version="1.0" encoding="utf-8" standalone="yes"?> <error
> xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
> <code></code>   <message xml:lang="en-US">An error occurred while
> processing this request.</message> </error>

根据 MarkStaffo 的请求打开详细信息。命令:

http://localhost:64638/WcfDataService1.svc/docSVtext?$top=1&$expand=docFieldDef

标记超时部分没有意义,因为它(假设)对 PK 击中一个小桌子。

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code/> <message xml:lang="en-US">An error occurred while processing this request.</message> -<innererror> <message>An error occurred while executing the command definition. See the inner exception for details.</message> <type>System.Data.EntityCommandExecutionException</type>
<stacktrace> at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Data.Services.Providers.BasicExpandProvider.ExpandedQueryable`1.GetEnumerator() at System.Data.Services.Providers.BasicExpandProvider.ExpandedQueryable`1.System.Collections.IEnumerable.GetEnumerator() at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable) at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService`1.HandleRequest()</stacktrace> -<internalexception> <message>Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.</message> <type>System.Data.SqlClient.SqlException</type> <stacktrace> at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)</stacktrace> </internalexception> </innererror> </error>

如果您在另一个选项卡中打开图像,您可以缩放。 在此处输入图像描述

4

0 回答 0