Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Linq - how to create a where statement with IS NOT NULL

how can i achieve this query with Nhibernate Linq?

var l = session.CreateQuery("from Auswahl a where a.Returnkey is not null").List<Auswahl>();

i tried this but it always returns an empty list.

var l = session.Linq<Auswahl>()
                   .Where(item => !String.IsNullOrEmpty(item.Returnkey))
                   .Select(item => item)
                   .ToList();
like image 735
blindmeis Avatar asked Aug 27 '10 07:08

blindmeis


1 Answers

Have you tried:

var l = session.Linq<Auswahl>()
                   .Where(item => item.Returnkey != null && item.Returnkey != "")
                   .Select(item => item)
                   .ToList();

I'm not sure that using String.IsNullOrEmpty would work, also it checks for two conditions - if it's NULL and if it's a blank empty string, how would that get translated into SQL? Might be worth having a look at SQL Profiler to see the raw SQL query it generates.

like image 79
Sunday Ironfoot Avatar answered Dec 12 '22 20:12

Sunday Ironfoot