TVF与EF6和WCF 5.6.3

时间:2015-03-14 22:01:17

标签: c# wcf odata entity-framework-6.1

在尝试将表值函数与Entity Framework 6.1.3和WCF 5.6.3一起使用时,我遇到了异常。最终目标是对这些TVF执行Restful查询,这些查询将结果表返回给请求者以进行进一步格式化。我遇到的一个问题是,我是否还需要将与TVF关联的关联表导入到模型中?

The server encountered an error processing the request. 
The exception message is 'Exception has been thrown by the target of an invocation.'. 
See server logs for more details. The exception stack trace is:

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
at System.Data.Services.DataServiceConfiguration.InvokeStaticInitialization(Type type) 
at System.Data.Services.DataServiceConfiguration.Initialize(Type type) 
at System.Data.Services.DataService`1.CreateConfiguration(Type dataServiceType, IDataServiceMetadataProvider provider, Boolean isInternallyCreatedProvider) 
at System.Data.Services.DataService`1.CreateProvider() 
at System.Data.Services.DataService`1.EnsureProviderAndConfigForRequest() 
at System.Data.Services.DataService`1.HandleRequest() 
at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) 
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

在模型类中,每个相应的TVF都有一个方法:

    [DbFunction("MyEntities", "func_Info")]
    public virtual IQueryable<func_Info_Result> func_Info(string buildNumber)
    {
        var bNumberParameter = bNumber != null ?
            new ObjectParameter("bNumber", bNumber) :
            new ObjectParameter("bNumber", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<func_Info_Result>("[MyEntities].[func_Info](@bNumber)", bNumberParameter);
    }

我在InitializeService中以典型的方式调用它,这是生成异常的地方:

config.SetEntitySetAccessRule("func_Info", EntitySetRights.AllRead);

编辑:内部例外:

<Message>The given name 'func_Info' was not found in the entity sets.

参数名称:名称

1 个答案:

答案 0 :(得分:0)

为了正确诊断核心问题,有必要查看WCF服务器日志中的内容。将以下内容添加到WCF服务的web.config中,以指定保存WCF日志的位置,然后再次生成异常。一旦捕获了错误日志,就可以使用调用异常的结果打开一个新问题。

<system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
</system.serviceModel>
<system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "C:\Temp\SvcLog\Traces.svclog" />
        </listeners>
      </source>
    </sources>
</system.diagnostics>

initializeData属性将设置日志的保存位置。