views:

82

answers:

1

hi, 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();
+1  A: 

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.

Sunday Ironfoot
thanks, you are right. but dont forget to write item.Returnkey != " " otherwise you get nothing from oracle. the Sql produced now looks like this: SELECT this_.ID as ID1_0_, this_.Programm as Programm1_0_, this_.Variante as Variante1_0_, this_.Returnkey as Returnkey1_0_, this_.Beschreibung as Beschrei5_1_0_FROM AUSWAHL this_WHERE (this_.Returnkey is not null and not (this_.Returnkey = ' ' /* :p0 */)) !there is a blank between ' ' :)
blindmeis
It's woth remembering that, for Oracle, null and the empty string are the same.
Diego Mijelshon