Bipul
Bipul

Reputation: 1367

How can we use case insensitive propertyName in criteria in nHibernate

In simple SQL we can write queries where the field names are case insensitive. For example, we want to query on Student table and it has one field called Name. We can write a query like this (in MS SQL):

select * from Student where name = "John"

See here we have used name instead of Name, but it still runs properly.

But when I write a criteria in nHibernate like this

session.createCriteria("Student")
.Add(Restrictions.Eq("name","John")).List()

It fails with the error could not resolve property: name of Student.

Is there any way we can make the field/property names case insensitive in criteria as direct SQL queries.

Thanks

Upvotes: 0

Views: 1242

Answers (2)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

Short answer: you can't. Property names are case sensitive.

Long answer: you can parse your user's input and use reflection to find the correct property names.

Upvotes: 1

UpTheCreek
UpTheCreek

Reputation: 32391

When doing a criteria query you are querying POCOs and their properties - and of course names in C# are case sensitive. As far as I know, HQL queryies are case sensitive too, so you probably are out of luck.

Upvotes: 0

Related Questions