Hey guys,
I'm trying to use a table-valued user-defined function (SQL Server) from NHibernate. However, I just can't seem to get the registration and/or the query right. Here is what I have...
Code:
CREATE FUNCTION GetIDs ()
RETURNS @IDs TABLE
(
ID int,
Level int
)
...
So it's a function that does not require any parameters, but that returns two int columns.
Next, I'm adding the function to my session factory (I know other people recommend to create your own dialect but I find this here easier):
Code:
sessionFactory.Dialect.Functions.Add("dbo.getids", new StandardSQLFunction("GetIDs"));
Then I try to create a query.
Code:
IQuery query = m_Session.CreateQuery("from dbo.GetIDs() as ids");
I get exceptions when I try to create the query. Obviously, I have tried various query variations (with and without the dbo., etc), and I get varying error messages, such as:
in expected: ( [from GetIDs() as ids]
undefined alias or unknown mapping: dbo [from dbo.GetIDs() as ids]I believe the problem is with adding the function. The main problem is that I have not found a single example that registers a table-valued function, only scalars.
Plus, the examples seem to be from NH 1.2.
Does anybody have a working NH 2.x example of how to use a table-valued UDF?
Thanks, Christoph