我在 Stackoverflow 和其他地方查看了许多示例和问题/答案。我不明白为什么我的 C# 看不到 Oracle SP。任何帮助,将不胜感激。
基本目标——
我有一个 Oracle SP(如下所示),它在返回参数 #1 中返回一个游标,并在 #2 和 #3 中给出了两个字符串参数。
我从 C# 调用 SP,试图将返回的结果集放入类 ExtractCoastalSurvey1SP 的 C# 列表中。(如下图)
我的代码在 Nhibernate 命令 GetNamedQuery 上崩溃了。
Oracle SP、NHibernate 映射 XML 文件、NHibernate 映射代码、调用代码和运行时错误转储都在下面。
如果您需要更多信息,请告诉我 - gmail.com 上的 sblalock。
谢谢您的帮助。解决这个问题,在我眼中提升为神!干杯,有一个祝福的一天!
M.斯科特·布莱洛克
运行时错误
Named query not known: PROC_MASSANDABUNDANCE Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: NHibernate.MappingException: Named query not known: PROC_MASSANDABUNDANCE
Source Error:
Line 7257:////query.SetParameter("SPECIESCODE_IN", "6186020202");
Line 7258: Line 7259: IQuery query = Session.GetNamedQuery("PROC_MASSANDABUNDANCE"); Line 7260: query.SetParameter("PROJECTCODE_IN", "P94"); Line 7261: query.SetParameter("SPECIESCODE_IN", "6186020202");
Source File: C:\Visual Studio 2008\Projects\SEAMAP\SEAMAP\SEAMAP\Service\DBRepository.cs Line: 7259
Stack Trace:
[MappingException: Named query not known: PROC_MASSANDABUNDANCE] NHibernate.Impl.AbstractSessionImpl.GetNamedQuery(String queryName) +509 SEAMAP.Services.DBRepository.ExtractCoastalSurvey1Collection(String[] _AreaArray, String _LatitudeRangeBegin, String _LatitudeRangeEnd, String _YearRangeBegin, String _YearRangeEnd, String _Season, String _State, String _DepthZone, String[] _SelectedMonthArray, String[] _SelectedYearArray, String[] _SelectedScientificNamesArray, String[] _SelectedCommonNamesArray, String[] _SelectedACCSPGridArray) in C:\Visual Studio 2008\Projects\SEAMAP\SEAMAP\SEAMAP\Service\DBRepository.cs:7259 SEAMAP.Controllers.ReportsController.ExtractCoastalSurvey(ExtractCoastalSurveyParameters _model) in C:\Visual Studio 2008\Projects\SEAMAP\SEAMAP\SEAMAP\Controllers\ReportsController.cs:277 lambda_method(ExecutionScope , ControllerBase , Object[] ) +140 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +178 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +24 System.Web.Mvc.<>c_DisplayClassd.b_a() +52 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +254 System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +192 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314 System.Web.Mvc.Controller.ExecuteCore() +105 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8699438 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
来自甲骨文
PROCEDURE PROC_MASSANDABUNDANCE
(p_recordset OUT SYS_REFCURSOR,PROJECTCODE_IN IN VARCHAR2, SPECIESCODE_IN IN VARCHAR2) AS
BEGIN
OPEN p_recordset FOR
SELECT * FROM TABLE;
END PROC_MASSANDABUNDANCE;
映射.HMB.XML 文件
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="SEAMAP" assembly="SEAMAP" >
<sql-query name="PROC_MASSANDABUNDANCE" Callable="true">
<query-param name="PROJECTCODE_IN" type="string" />
<query-param name="SPECIESCODE_IN" type="string" />
<return class="SEAMAP.Models.ExtractCoastalSurvey1SP" />
{ call PROC_MASSANDABUNDANCE(:PROJECTCODE_IN :SPECIESCODE_IN) }
</sql-query>
</hibernate-mapping>
C# 代码
映射代码
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(OracleClientConfiguration.Oracle10
.ConnectionString(c => c.FromConnectionStringWithKey(connString))
.ShowSql())
.ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
.Mappings(m => m.HbmMappings.AddFromAssemblyOf<Project>())
.BuildSessionFactory();
}
调用代码
IQuery query = Session.GetNamedQuery("PROC_MASSANDABUNDANCE");
query.SetParameter("PROJECTCODE_IN", "P94");
query.SetParameter("SPECIESCODE_IN", "6186020202");
return query.List<ExtractCoastalSurvey1SP>();