06-06-2012 03:47 AM
Hi ,
I'm Executing a SP ,
String[] DataColumn = { "ProductId", "Line", "Name", "Description", "VBDiscount", "List", "Discount", "Sell", "Quantity", "Extendedcalculatedfiled", "StockWeight", "WTCalculated", "Effectivedate" };
NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper();
NHibernate.IQuery query = (NHibernate.IQuery)session.GetNamedQuery("SP_Oppor tunityProducts");
query.SetParameter("OPPORTUNITYID", "O0L6XA100003");
System.Collections.IList results = query.List();
System.Collections.Generic.IList<object> tempList = query.List<object>();
int i = 0;
foreach (object[] data in tempList)
{
if (i < 5)
{
Sage.Platform.ComponentModel.ComponentView cv = new Sage.Platform.ComponentModel.ComponentView(DataCol umn, data);
results.Add(cv);
i++;
}
else { break; }
}
result = results;
It Shows the Error ,
http://XXXX:XXXX/SlxClient/Opportunity.aspx?entity
Thanks
Vinoth Xavier
Solved! Go to Solution.
06-06-2012 11:09 AM
Hello Vinoth -
I am not an expert on nHibernate, but I might be able to offer at least a little guidance.
The session.GetNamedQuery might not be what you are looking for.
I believe that nHibernate supports executing SQL statements, something like:
IQuery query = session.CreateSQLQuery("exec SP_OpportunityProducts @OpportunityId=opportunityid:, @OtherId=
therid");
query.SetString("opportunityid", opportunity.id);
query.SetString("otherid", otherid);
query.Execute();
Note that I'm not positive on the last bit with query.Execute(), maybe it is query.List();
The thing is, I'm not sure how the mapping from a raw SQL result set back into the object model is handled.
You might look into HQL to see if there is a cleaner way to handle calling a database stored proceedure that will return a result set.
Also note - Sage SalesLogix Web v7.5.4 is using nHibernate v2.12 I believe. Keep that in mind when searching the net looking for examples. The next major release of Sage SalesLogix web will use nHibernate v3.x (I think v3.2 but do not hold me to that).
06-07-2012 12:00 AM
Hi Tood,
Thanks for your valuable reply. Its Help Me lot, But now I face an error,
Error,
Failed to parse SQL. At System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbComm and.ExecuteReader() at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(ID bCommand cmd) at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) at NHibernate.Loader.Loader.DoQuery(ISessionImplement or session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLa zyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplemento r session, QueryParameters queryParameters)