where和order by使用

where 可以让我们的搜索结果进行一层过滤帅选。

public IList<News> Where()

        {

            return session.CreateQuery("from News n where n.Title = '开学典礼'").List<News>();

        }Code language: PHP (php)

where 子句允许出现的表达式包括了在 SQL 中的大多数情况:
• 数学操作符: +, -, *, /
• 真假比较操作符: =, >=, <=, <>, !=, like
• 逻辑操作符: and, or, not
• 字符串连接操作符: ||
• SQL 标量函数: upper(),lower()
• 没有前缀的( ):表示分组
• in, between, is null
• 位置参数: ?
• 命名参数: :name, :start_date, :x1
• SQL 文字: ‘foo’, 69, ‘1970-01-01 10:00:01.0’
• 枚举值或常量: Color.Tabby

orderby对结果进行排序

按照任何返回的类或者组件的属性排序: asc 升序、 desc 降序

public IList<News> Orderby()

        {

            return session.CreateQuery("from News n order by n.AddTime asc, n.Title desc").List<News>();

        }Code language: PHP (php)

如果查找所有 则可以把select 去掉 之间from xxx 就可以了。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注