NHibernate, how to read NamedQuery result metadata?
I have an sql-query define on my nhibernate mapping file, that call an stored procedure to select some records.
<sql-query name="sp_MYSP">
exec MYDBSP :param1, :param2, :param3
</sql-query>
On code, I call the named query in this way:
IQuery myQuery= Session.GetNamedQuery("sp_MYSP");
myQuery.SetString("param1", p1);
myQuery.SetString("param2", p2);
myQuery.SetString("param3", p3);
to get results I use "List" method
myQuery.List();
but in this way it return a list of objects without any开发者_如何学C meta information...like columname. I would read result like a datatable to get value of specific property...how can I do?
The selected records don't represents any entity of my domain modal, but only a collection of data use for a specific process.
If you are not mapping that query to an entity and expect a datatable, why use NHibernate at all?
You can still get a connection from NHibernate if you are actually using it for the rest of your data (session.Connection) and create a raw ADO.NET command from there.
You're right.
However I found another solution from this article publish on codeprojet: http://www.codeproject.com/KB/tips/Execute_SQL_Nhibernate.aspx
Fit for my scenario.
精彩评论