ODATA URI查询从FK扩展到PK

时间:2012-06-28 21:29:02

标签: .net odata wcf-data-services

从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 

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

未能成功拦截.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

Fiddler失败

> # 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>

如果您在另一个标签页中打开图像,则可以进行缩放。 enter image description here

0 个答案:

没有答案