5

i'm trying to query arbitrary sql data with nhibernate, it works fine as long as i don't use the Futures feature, however, when I use Futures, the data doesn't get passed into the ResultSetTransformer.

Example Code:

public class TestResultSetTransformer : IResultTransformer
{
    public object TransformTuple(object[] tuple, string[] aliases)
    {
        return tuple;
    }

    public IList TransformList(IList collection)
    {
        return collection;
    }
}
public void Foo(ISession sess){
        var x = sess.CreateSQLQuery("select * from MailEvent").SetResultTransformer(new TestResultSetTransformer()).Future<object[]>();
        var xprime = sess.CreateSQLQuery("select * from MailEvent").SetResultTransformer(new TestResultSetTransformer()).List<object[]>();
        foreach(var y in x)
        {

        }
}

in this example, the futures query returns a list of empty object arrays that has the correct row count, when i debug into it, the object[] tuple is empty, however with the list query, it works as expected.

Bryan Pedlar
  • 138
  • 1
  • 7

1 Answers1

0

You may wish to try something like this:

public class MailEvent
{
    public virtual int Id{get;set;}
    public virtual string Message{get;set;}
}

public IEnumerable<MailEvent> GetMailEvents(ISession session)
{
    return session.CreateSQLQuery("select Id, Message from MailEvent")
                  .SetResultTransformer(Transformers.AliasToBean<MailEvent>())
                  .Future<MailEvent>();        
}

This should convert the arbitrary SQL data to what you need, assuming you know the destination format

Jon Bates
  • 3,055
  • 2
  • 30
  • 48
  • I didn't do two queries (or even compile the code I just wrote), but the pattern is sound. – Jon Bates Sep 26 '12 at 21:10
  • 1
    it turns out that this wasn't working for me because there is a bug in NHibernate. I've reported it on their JIRA and hopefully they're working on it. Specifically, ResultTransformers don't seem to work in conjunction with futures queries. – Bryan Pedlar Jan 29 '13 at 15:56
  • And here is the link to your JIRA issue. https://nhibernate.jira.com/browse/NH-3222 – Stefan Steinegger Jun 06 '13 at 09:13
  • Same problem here, definitely a bug. – cbp Jul 26 '13 at 06:27
  • 1
    It's still buggy with 3.3.3.4000, still there in almost 2 years :( – Stefano.net May 12 '14 at 14:37
  • Definitely getting empty objects in 3.3.1.4000 - anyone know if we've seen fixes for this in the future? @Stefano.net – steamrolla Mar 31 '16 at 21:49
  • 2
    Hi, it's been fixed from version 4 – Stefano.net Apr 01 '16 at 06:26
  • I was a bit confused, because, I was seeing multiple bugs on NHibernate's JIRA that said completed (and should've been included in the old version I was on). Upgraded from nuget to 4.0.4, and, the fix is there. – steamrolla Apr 01 '16 at 16:14