views:

223

answers:

1

Hi,

Im being a bit lazy in NHibernate and using Session.CreateSqlQuery(...) instead of doing the whole thing with Lambda's. Anyway what struct me is that there seems to be a problem converting some of the types returned from (in this case the MySQL) DB into native .Net tyes.

The query in question looks like this....

     IList<Client> allocatableClients =
                    Session.CreateSQLQuery(
                      "select clients.id as Id, clients.name as Name, clients.customercode as CustomerCode, clients.superclient as SuperClient, clients.clienttypeid as ClientType " +
...
...
.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Client))).List<Client>();

The type in the database of SuperClient is a bit(1) and in the Client object the type is a bool.

The error received is:

System.ArgumentException: Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'.

It seems strange that this conversion cannot be completed.

Would be greatful for any ideas.

Thanks.

A: 

No need to do any Lambdas (even though they are fun!). If CLient is a mapped class then you can use the core NHibernate method `CreateCriteria<>'. It is very simple.

        session
            .CreateCriteria<Client>()
            .List<Client>();

If Client isn't mapped then I would create a property SuperUser_Long and wrap it with SuperUser

ondesertverge
My bad! I should have included the rest of my query which has some where clauses which I wanted to avoid "lambda-ing."
RemotecUk
No need for lambdas on the where clause either :) - use `.Add()` on the `CreateCriteria` to add a `SimpleExpression` or a `Restriction`
ondesertverge