locked
Error from WCF Data Service when expanding multiple navigation properties RRS feed

  • Question

  • I have a service reference to a WCF Data Service (5.0).  Everything runs well when expanding a single navigation property in an entity query.  However when trying to expand multiple navigation properties the service returns an error.

    //Here is a sample of the code expanding multiple navigation properties resulting in an error from the data service.
    
     var e = from b in entCont.Organizations.Expand("Bureaux").Expand("Employees").OfType<Chief>()
                        where b.Id == "1000"
                        select b;
    
    //Here is the same code expanding a single navigation property which executes successfully.  Expanding either of the navigation properties works.
    
     var e = from b in entCont.Organizations.Expand("Bureaux").OfType<Chief>()
                        where b.Id == "1000"
                        select b;

    The error message returned from the service is:

    <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">An error occurred while processing this request.</m:message></m:error>
    I am sure I am overlooking something obvious but any help pointing me in the right direction as to why I am unable to expand the multiple navigation properties would be appreciated.

    Below is the stack trace.

    System.Data.Services.Client.DataServiceQueryException was unhandled by user code
      HResult=-2146233079
      Message=An error occurred while processing this request.
      Source=Microsoft.Data.Services.Client
      StackTrace:
           at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
           at System.Data.Services.Client.DataServiceQuery`1.Execute()
           at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
           at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
           at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
           at WebApplication1.Controllers.EmployeeOrganizationController.getChief(String orgId) in c:\Users\rwaten\Documents\Visual Studio 2013\Projects\EmployeeOrganization\WebApplication1\Controllers\EmployeeOrganizationController.cs:line 50
           at lambda_method(Closure , ControllerBase , Object[] )
           at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
           at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
           at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
           at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
           at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c()
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e()
      InnerException: System.Data.Services.Client.DataServiceClientException
           HResult=-2146233079
           Message=<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="<m:code">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">An error occurred while processing this request.</m:message></m:error>
           Source=Microsoft.Data.Services.Client
           StatusCode=500
           StackTrace:
                at System.Data.Services.Client.QueryResult.ExecuteQuery()
                at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
           InnerException:


    • Edited by Rolland3100 Friday, September 27, 2013 6:03 PM
    Friday, September 27, 2013 4:36 PM

Answers

  • Should have looked a bit more before asking the question above.  I found the problem.  The ProviderManifestToken in the EDMX was set for 2008.  We are running against 2005.  Updating the value and rebuilding the solution resolved the problem.
    Monday, September 30, 2013 6:32 PM

All replies

  • Hello,

    From my opinion, if relationship in the three tables is organizations one-to-many Bureaux and organizations one-to-many Employees, it should be ok.

    So I guess that if the relationship is organizations one-to-many Bureaux and Bureaux one-to-many Employees.

    If it is, then we can have a try change it to:

    var e = from b in entCont.Organizations.Expand("Bureaux").Expand("Bureaux.Employees").OfType<Chief>()
    
    where b.Id == "1000"
    
    select b;
    

    Because the organizations does not have a direct relationship with Employees.

    If this does not work for you, please let me know.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 30, 2013 11:12 AM
    Moderator
  • Fred - Thank you for your reply.  That does not appear to be the issue however.  The navigation properties Bureaux and Employees are on the Chief class.  It is also possible to expand either property on the Chief class individually.  The problem is when I attempt to open them as part of a single query.

    Just a reminder, the Expand statement takes a string that is in the form of a url resource path for your odata starting at the returned object in your query request.  The object dot notation in your code example would fail.

    Very Respectfully,

    Rolland

    Monday, September 30, 2013 12:24 PM
  • To understand this I think you need to get the real error from the server. By default the server responds with a generic error for security reasons. Please follow this blog post to enable detailed error reporting and try again to get the actual reason.

    http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

    Thanks,


    Vitek Karas [MSFT]

    Monday, September 30, 2013 5:09 PM
    Moderator
  • Vitek - Thank you for your reply.  I do have UseVerboseErrors enabled.  I did not have the decorator on the DataService class.  I added that and ran the project again.  Here is the trace that I received.  Thank you for any feedback you can provide.

    Respectfully,

    Rolland

    System.Data.Services.Client.DataServiceQueryException was unhandled by user code
      HResult=-2146233079
      Message=An error occurred while processing this request.
      Source=Microsoft.Data.Services.Client
      StackTrace:
           at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
           at System.Data.Services.Client.DataServiceQuery`1.Execute()
           at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
           at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
           at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
           at WebApplication1.Controllers.EmployeeOrganizationController.getChief(String orgId) in c:\Users\rwaten\Documents\Visual Studio 2013\Projects\EmployeeOrganization\WebApplication1\Controllers\EmployeeOrganizationController.cs:line 62
           at lambda_method(Closure , ControllerBase , Object[] )
           at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
           at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
           at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
           at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
           at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c()
           at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e()
      InnerException: System.Data.Services.Client.DataServiceClientException
           HResult=-2146233079
           Message=<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="<m:code">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">An error occurred while processing this request.</m:message><m:innererror><m:message>An error occurred while executing the command definition. See the inner exception for details.</m:message><m:type>System.Data.EntityCommandExecutionException</m:type><m:stacktrace>   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)&#xD;
       at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)&#xD;
       at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)&#xD;
       at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()&#xD;
       at System.Data.Services.Providers.BasicExpandProvider.ExpandedQueryable`1.GetEnumerator()&#xD;
       at System.Data.Services.Providers.BasicExpandProvider.ExpandedQueryable`1.System.Collections.IEnumerable.GetEnumerator()&#xD;
       at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)&#xD;
       at System.Data.Services.QueryResultInfo.MoveNext()&#xD;
       at System.Data.Services.Providers.DataServiceExecutionProviderWrapper.GetSingleResultFromRequest(SegmentInfo segmentInfo)&#xD;
       at System.Data.Services.DataService`1.CompareETagAndWriteResponse(RequestDescription description, IDataService dataService, IODataResponseMessage responseMessage)&#xD;
       at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService, IODataResponseMessage responseMessage)&#xD;
       at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)&#xD;
       at System.Data.Services.DataService`1.HandleRequest()</m:stacktrace><m:internalexception><m:message>Type datetime2 is not a defined system type.&#xD;
    Type datetime2 is not a defined system type.&#xD;
    Type datetime2 is not a defined system type.&#xD;
    Type datetime2 is not a defined system type.&#xD;
    Type datetime2 is not a defined system type.</m:message><m:type>System.Data.SqlClient.SqlException</m:type><m:stacktrace>   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)&#xD;
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)&#xD;
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)&#xD;
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)&#xD;
       at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()&#xD;
       at System.Data.SqlClient.SqlDataReader.get_MetaData()&#xD;
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, SqlDataReader ds)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task, Boolean asyncWrite)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)&#xD;
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)&#xD;
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)&#xD;
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)&#xD;
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)</m:stacktrace></m:internalexception></m:innererror></m:error>
           Source=Microsoft.Data.Services.Client
           StatusCode=500
           StackTrace:
                at System.Data.Services.Client.QueryResult.ExecuteQuery()
                at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
           InnerException:

    Monday, September 30, 2013 5:41 PM
  • Vitek - I think I may have stumbled on the cause.

    There is a mention in the trace of a data type of DateTime2.  I went ahead and ran SQL profiler and ran the project.  The request sent to the database included some casts as part of the union statement to a data type of datetime2.  I am using SQL Server 2005 which does not have a datetime2 type so the database is throwing an error.

    Is there a parameter which defines the version of SQL Server EF should be formatting it's queries for?

    Rolland

    Monday, September 30, 2013 6:16 PM
  • Should have looked a bit more before asking the question above.  I found the problem.  The ProviderManifestToken in the EDMX was set for 2008.  We are running against 2005.  Updating the value and rebuilding the solution resolved the problem.
    Monday, September 30, 2013 6:32 PM
  • Glad you were able to solve this :-)

    Thanks,


    Vitek Karas [MSFT]

    Monday, September 30, 2013 7:29 PM
    Moderator