Discussion:
[nhusers] Forcing .ToLower() on parameter to run in database.
Andreas Eriksson
2018-10-30 15:26:44 UTC
Permalink
I have the following linq query

session.Query<Car>().Where(c => c.Name.ToLower() == name.ToLower()).Select(c
=> c.Id)

which translates into the following sql query
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=:p0;:p0 = 'volvo'


How can I force NHibernate to use lower for the parameter as well?
I want the sql to look like this:
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=lower(:p0);:p0 = 'Volvo'

/Andreas
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Gunnar Liljas
2018-10-30 16:01:49 UTC
Permalink
Ï think you'll have to create your own "ToLowerParameter" extension method
and use that instead of ToLower. Mark the method with

[LinqExtensionMethod("lower")]

"Since NHibernate v5.0, the Linq provider will no more evaluate in-memory
the method call even when it does not depend on the queried data."

In other words, it will be converted into a SQL call.

/G


Den tis 30 okt. 2018 kl 16:54 skrev Andreas Eriksson <
Post by Andreas Eriksson
I have the following linq query
session.Query<Car>().Where(c => c.Name.ToLower() == name.ToLower()).Select
(c=> c.Id)
which translates into the following sql query
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=:p0;:p0 = 'volvo'
How can I force NHibernate to use lower for the parameter as well?
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=lower(:p0);:p0 = 'Volvo'
/Andreas
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Andreas Eriksson
2018-10-30 17:26:42 UTC
Permalink
Thanks Gunnar,

that work as expected.

I was trying to implement it by overriding BaseHqlGeneratorForMethod but
your solution is much simpler.
Post by Gunnar Liljas
Ï think you'll have to create your own "ToLowerParameter" extension method
and use that instead of ToLower. Mark the method with
[LinqExtensionMethod("lower")]
"Since NHibernate v5.0, the Linq provider will no more evaluate in-memory
the method call even when it does not depend on the queried data."
In other words, it will be converted into a SQL call.
/G
Den tis 30 okt. 2018 kl 16:54 skrev Andreas Eriksson <
Post by Andreas Eriksson
I have the following linq query
session.Query<Car>().Where(c => c.Name.ToLower() == name.ToLower()).
Select(c=> c.Id)
which translates into the following sql query
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=:p0;:p0 = 'volvo'
How can I force NHibernate to use lower for the parameter as well?
select car0_."Id" as col_0_0_ from "Car" car0_ where lower(car0_.
"Identifier")=lower(:p0);:p0 = 'Volvo'
/Andreas
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...