Search code examples
.netnhibernatesqldatareaderdatareader

NHibernate's equivalent of LINQ to SQL's and EF's Translate<T>()


I have a query that due to performance reasons I need to craft the actual command using raw ADO.NET (it involves table-valued parameters). With LINQ to SQL or EF, I could simply pass the DbDataReader that was returned by DbCommand.ExecuteReader() to the DataContext.Translate<T>(DbDataReader) or ObjectContext.Translate<T>(DbDataReader) method and it would convert the result-set to objects, returning an IEnumerable<T>.

Is there any equivalent API in NHibernate that I can either pass a DbDataReader/IDataReader or even an DbCommand/IDbCommand and get NHibernate entities back?

Or perhaps there's a way to intercept the construction of the command created by ISession.CreateQuery(string) so that I could modify the underlying DbCommand to work the way I need to?


Solution

  • You can probably create a custom UserType to handle the table-valued parameter.

    NHibernate does not expose the DataReader -> entities transformation in any public methods.