Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top