代码之家  ›  专栏  ›  技术社区  ›  Bipul

在nHibernate中如何在条件中使用不区分大小写的属性名

  •  0
  • Bipul  · 技术社区  · 15 年前

    在简单的SQL中,我们可以在字段名不区分大小写的地方编写查询。例如,我们希望查询 Student 表中有一个字段名为 Name . 我们可以编写这样的查询(在MS SQL中):

    select * from Student where name = "John"
    

    看这里我们用过 name 而不是 名字 但它仍然正常运行。

    但是当我写一个这样的标准时

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

    它因错误而失败 could not resolve property: name of Student .

    在条件中,是否可以将字段/属性名作为直接SQL查询设置为不区分大小写。

    谢谢

    2 回复  |  直到 15 年前
        1
  •  1
  •   Diego Mijelshon    15 年前

    简短回答:不能。属性名称区分大小写。

    答案很长:您可以解析用户的输入并使用反射来查找正确的属性名。

        2
  •  0
  •   UpTheCreek    15 年前

    在进行条件查询时,您正在查询POCO及其属性——当然,C中的名称区分大小写。据我所知,hql查询也区分大小写,所以你可能走运了。