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();

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 ' ' :)
It's woth remembering that, for Oracle, null and the empty string are the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.