views:

20

answers:

1

I'm pulling my hair out over here and I'm not sure what's causing it.

I have the following LINQ query:

return Session.Linq<CandidateAccountEntity>().SingleOrDefault(p => p.UserName.ToLower().Equals(userName.ToLower()));

and its throwing the following error:

Index was out of range. Must be non-negative and less than the size of the collection.

If I try to wrap it with a check of:

if(Session.Linq<CandidateAccountEntity>().Any()) {...}

then I get the following error:

could not execute query [ SELECT count(*) as y0_ FROM [CandidateAccountEntity] this_ inner join CFG.Account this_1_ on this_.AccountEntity1_id=this_1_.AccountId ] [SQL: SELECT count(*) as y0_ FROM [CandidateAccountEntity] this_ inner join CFG.Account this_1_ on this_.AccountEntity1_id=this_1_.AccountId]

with an inner exception of:

{"Incorrect syntax near '`'."}

Any help would be greatly, greatly apperciated. I don't want to get stuck here on friday afternoon :/

+1  A: 

ToLower is not supported in the NH 2.x Linq provider. It works with the integrated provider in 3.x.

Diego Mijelshon
Hmm, well crap. Is there anyway to ignore case then?
Chance
Depending on the DB, you could use a case-insensitive collation for that field.
Diego Mijelshon