I want to get a list of roles for a registered user.
Below is a snippet of code that reads user roles from a database.
ISession session = NHibernateHelper.GetCurrentSession(); var data = from s in session.Linq<ApplicationUserRole>() where s.AppUser.ID = 1 select s.Role.Name; List<Role> list = data.ToList();
AppUser: Custom Object Role: Role. Since there is no data in the database for user id 1, it does not return anything.
The return type data is NHibernate.Linq.Query and is not null.
It causes the following error when I try to convert it to ToList ();
"The index was out of range. Non-negative and smaller than the size of the collection. Parameter name: index"
How to handle empty result sets?
source share