7

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();
blindmeis
  • 22,175
  • 7
  • 55
  • 74

1 Answers1

7

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
  • 12,840
  • 15
  • 75
  • 91
  • 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 Aug 27 '10 at 10:46
  • It's woth remembering that, for Oracle, null and the empty string are the same. – Diego Mijelshon Aug 27 '10 at 14:05