Nhibernate dynamically return result set

135 views
Skip to first unread message

Ayy

unread,
Dec 2, 2011, 3:15:12 AM12/2/11
to nhu...@googlegroups.com
Hi,

We have requirement for dashboard dynamically generate data based Stored procedure. When we use createsqlquery or iquiry or named query, it's returning list and storing to memory.

We have sqldatareader to read data one by one from SQL server.

Now I am looking similar way can we implement using nhibernate

Please provide your thoughts /suggestions.


Thanks & Regards,
Ayyappa Kolli.


Jason Meckley

unread,
Dec 2, 2011, 8:52:11 AM12/2/11
to nhu...@googlegroups.com
I don't quite understand what your question is, other than you want to replace a stored proc with NH. sure it's possible, but there isn't nearly enough information here to say how to do that.

That fact that you have a single proc driving the entire dashboard doesn't seem plausible, but it could be one enormous proc. or it's just one proc to get things started and then additional queries to load the specifics of each widget.

if your problem is you don't want NH to load all the results before processing. then you need to provide your own IList implmentation. here is post about the feature: http://ayende.com/blog/4548/nhibernate-streaming-large-result-sets

Kolli Ayyappa

unread,
Dec 2, 2011, 12:09:24 PM12/2/11
to nhu...@googlegroups.com
Hi,
 
Thanks for your response.
 
We have stored precedure that will retrun multiple results set.
For eg: Exec SP
Retrun result set from SP : Object collection1, Object collection2, objection collection 3 etc..
In SQL we can use SQLdataReader to read data one by one from retrun result set collection from SP. We are looking similar way can we implement in nhibernate?
 
I am seeing IMultiQuery looks same, but my conerns, can we execute SP using IMultiquery?
 
Thanks,
Ayyappa Kolli


 

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/6xVrf9XlEq4J.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Jason Meckley

unread,
Dec 2, 2011, 1:26:24 PM12/2/11
to nhu...@googlegroups.com
I don't think NH supports multiple record sets in the identical manner that your proc does. However NH does offer deferred execution of commands into a single remote call with Future, FutureValue and MultiQuery members.

so you can do something like this:
var results1 = session.queryover<foo>().Where(...).Future();
var results2 = session.queryover<bar>().Where(...).FutureValue();
var results3 = session.queryover<fu>().Where(...).Future();
foreach(var result in results1)
{
   // at this point all 3 queries are executed.
}

this is very useful when loading aggregate root with multiple child collections
var root = session.QueryOver<Root>().Where(r=>r.Id = id).FutureValue();
session.QueryOver<Root>().Fetch(r=>r.Children).Eager.Where(r=>r.Id = id).FutureValue();
session.QueryOver<Root>().Fetch(r=>r.OtherChildren).Eager.Where(r=>r.Id = id).FutureValue();

var result = root.Value; //at this point all 3 queries are executed.

If you are looking to have NH execute your stored proc for you, then that is a different issue altogether. To start it doesn't make much sense to introduce NH if you are going to keep the proc. if you are going to approach it this way, then get the connection from the session and execute the proc as you normally would.
var connection = session.Connection;
using(var command = connection.CreateCommand())
{
   comand...
   return command.ExecuteReader();
}

Ayy

unread,
Dec 2, 2011, 3:04:38 PM12/2/11
to nhu...@googlegroups.com, nhu...@googlegroups.com
Thank you for your response



Thanks & Regards,
Ayyappa Kolli.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/uMRsQ2FeqWMJ.
Reply all
Reply to author
Forward
0 new messages