数据库组件 Hxj.Data (十一) (where条件)
2010-05-19 13:41
513 查看
在前几节的例子中都生成where之后的条件,例如:
代码中这些就是生成条件,对应sql就是 categoryid=2
归根到底这句代码返回回来的是一个WhereClip.
这个是一个空值,也就是无条件。
不会生成where条件。
条件的组合
两个条件同时成立:
等效sql就是 unitprice>1 and categoryid=2
两个条件或
等效sql就是 unitprice>1 or categoryid=2
也就是 && 表示左右条件同时成立
|| 表示左右条件有一个成立即可
组件重载了操作符:
写法和sql类似,也方便记忆与书写。
当然也可等效写为:
where.And 等效于 &&
where.Or 等效于 ||
优先级可用()括起来,如下
等效sql就是 (productname like ‘%apple%' and unitprice>1) or categoryid=2
也等效于
下一节将讲述Field中生成条件的方法。
Products._.CategoryID == 2
代码中这些就是生成条件,对应sql就是 categoryid=2
归根到底这句代码返回回来的是一个WhereClip.
WhereClip where = WhereClip.All;
这个是一个空值,也就是无条件。
不会生成where条件。
条件的组合
两个条件同时成立:
Products._.UnitPrice > 1 && Products._.CategoryID == 2
等效sql就是 unitprice>1 and categoryid=2
两个条件或
Products._.UnitPrice > 1 || Products._.CategoryID == 2
等效sql就是 unitprice>1 or categoryid=2
也就是 && 表示左右条件同时成立
|| 表示左右条件有一个成立即可
组件重载了操作符:
C# | SQL |
> | > |
>= | >= |
<= | <= |
< | < |
== | = |
!= | <> |
当然也可等效写为:
WhereClip where = WhereClip.All; where = where.And(Products._.UnitPrice > 1); where = where.Or(Products._.CategoryID == 2);
where.And 等效于 &&
where.Or 等效于 ||
优先级可用()括起来,如下
(Products._.ProductName.Contain("apple") && Products._.UnitPrice > 1) || Products._.CategoryID == 2
等效sql就是 (productname like ‘%apple%' and unitprice>1) or categoryid=2
也等效于
WhereClip where = WhereClip.All; where = where.And(Products._.ProductName.Contain("apple")); where = where.And(Products._.UnitPrice > 1); where = where.Or(Products._.CategoryID == 2);
下一节将讲述Field中生成条件的方法。
相关文章推荐
- 数据库组件 Hxj.Data (十一) (where条件)
- 数据库组件 Hxj.Data (三十一)(MySQL篇)
- 数据库组件 Hxj.Data (二十六)(Oracle 配置)
- 数据库组件 Hxj.Data (四)(添加操作篇)
- 数据库组件 Hxj.Data(七) (sql篇)
- 数据库组件 Hxj.Data (十二) (模糊查询、简单的in,not in查询)
- 数据库组件 Hxj.Data (五)(更新操作篇)
- 数据库组件 Hxj.Data (二十九)(DbSession的推荐写法)
- 数据库组件 Hxj.Data (十九) (事务二)
- 数据库组件 Hxj.Data (三十一)(MySQL篇)
- 数据库组件 Hxj.Data (六)(删除操作篇)
- 数据库组件 Hxj.Data (十六) (查询的字段)
- 数据库组件 Hxj.Data (二)(实体生成工具)
- 数据库组件 Hxj.Data (八)(存储过程篇)
- 数据库组件 Hxj.Data (十二) (模糊查询、简单的in,not in查询)
- 数据库组件 Hxj.Data (三)(查询操作篇)
- 数据库组件 Hxj.Data (二十五)(数据库连接配置 - connectionStrings节点)
- 数据库组件 Hxj.Data (八)(存储过程篇)
- 数据库组件 Hxj.Data (十三) (子查询)
- 数据库组件 Hxj.Data (十四) (联合查询)