views:

4778

answers:

1

Hello.

There is need for quering NHibernate for several instances of the entity. I've tried following code, but it failed with wired NRE indepth of NHibernate.

var query = NHibernateSession.CreateQuery("from User u where u.id in (:ids)");
query.SetParameterList("ids", new Guid[]);
query.ToList();

It looks like common problem - any suggestions?

Update This only occurs if array is empty - question closed.

+1  A: 

:ids would be an empty Guid array, wouldn't it? You're asking NHibernate to give you users where the id is inside a non-initialized array of Guid.

Gonzalo Quero
Yes, I know it. It's just example. Replacenew Guid[]bynew [] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(),Guid.NewGuid() }
Artem Tikhomirov
But Guid is supposed to give you that, unique ids. You're asking for ids on a database that are the same that some new unique ids. If I'm not getting it, tell me and I'll delete this answer ;)
Gonzalo Quero
You're not getting it, but you are right :) Error occurs only on empty array. I've just tested it on empty DB.
Artem Tikhomirov