c# - NHibernate JOIN to temp table -


i want work in sql, populating temp table, , join temp table using nhibernate createsqlquery final results. on version 1.2.0.4000 of nhibernate , seem having problems accessing temp table in later query, though i'm in same session (i believe means i'm in same sql session/connection well). below simplified version of code

public void work() {     sqlconnection connection = (sqlconnection)session.connection;      sqlcommand command = new sqlcommand                      {                          commandtype = commandtype.text,                          commandtext = "select id = 1 #temptable",                          connection = connection,                      };      if ( session.transaction != null && session.transaction.isactive )     {         session.transaction.enlist( command );     }      command.executenonquery();      // simplified example, should have temp table #temptable 1 row containing values id = 1      // trying fetch list of account objects id exists in #temptable.     // @ point, error "invalid object name '#temptable'."     ilist<account> accounts = session.createsqlquery(@"         select *           account           join #temptable tt             on a.id = tt.id")         .addentity("a", typeof(account))         .list<account>();      // work on accounts list } 

sessions connections on demand, not guaranteed same connection back. there 2 possibilities same connection every time:

  • using sessionfactory.opensession(myconnection); ties session provided connection.
  • implement iconnectionprovider pooling of connections

option 1 definitly easier


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -