开发者

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):

s开发者_开发知识库elect * 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜