MyGeneration学习笔记(7) :dOOdad的String Properties和动态查询

简介:

     主要是摘自dOOdad文档,另外加了些自己的注释,纠正了个别描述不准确的地方。

1.   String Properties

        dOOdad另一个非常有用的特点就是“String Properties”,实现了统一处理字符串类型列和非字符串类型列的空值问题。For each data column in the dOOdad, there is a string property in addition to the column property。(ps:虽然文档上是这么说的,但是在数据库中数据类型为Picture的列,在dOOdad中是没有string Property的)
    例如:

emps.Salary 和emps.s_Salary
emps.HireDate 和 emps.s_HireDate
检查空值:
if (emps.s_Salary  ==   "" )
if (emps.s_HireDate  ==   "" )
设置空值:
emps.s_LastName 
=   "" ;
emps.s_HireDate 
=   ""

 

2.    动态查询:
            dOOdad也提供了动态查询的功能,使用动态查询功能,可以避免写一些散杂的查询存储过程来进行查询。
   另外,dOOdad提供的动态查询是生成参数化的查询语句,从而可以避免SQL注入攻击。
  2.1    WhereParameter类 中的Enum:
          (1) 联合:(WhereParameter.Conj)
                            And
                            Or
                            UseDefault
          (2) 排序:(WhereParameter.Dir)
                             ASC
                            DESC
          (3) 运算:(WhereParameter.Operand)
                             Between
                             Equal
                             GreaterThan
                             GreaterThanOrEqual
                              In
                              IsNotNull
                              IsNull
                              LessThan
                              LessThanOrEqual
                              Like
                              NotEqual
                              NotIn
                              NotLike

  2.2 使用动态查询:
     (1).  查询符合条件的所有行:

emps.Where.LastName.Value  =   " %A% " ;
emps.Where.LastName.Operator 
=  WhereParameter.Operand.Like;
// Note: Conjuction not Conjunction
emps.Where.HireDate.Conjuction  =  WhereParameter.Conj.Or;
emps.Where.HireDate.BetweenBeginValue 
=   " 2001-01-01 00:00:00.0 " ;
emps.Where.HireDate.BetweenEndValue 
=   " 2001-12-31 23:59:59.9 " ;
emps.Where.HireDate.Operator 
=  WhereParameter.Operand.Between;
// 根据上面的条件,dOOdad会自动生成查询语句
emps.Query.Load();
// ps:Load()方法有重载,我们也可以给Load方法传入Sql查询条件(Sql SELECT语句的Where子句),而不用像上面一样写一堆的赋值。

  
     (2).  返回指定的列集(此时不能调用Save(),因为除此之外的其他列在数据库中存在,而在emps对象的_dataTable中不存在,而在Save中,需要提供所有列的数据作为存储过程的参数):
 emps.Query.AddResultColumn(Employees.ColumnNames.EmployeeID);
 emps.Query.AddResultColumn(Employees.ColumnNames.LastName);
 emps.Query.Load();

     (3). 排序
          emps.Query.AddOrderBy(Employees.ColumnNames.HireDate,WhereParameter.Dir.DESC);

     (4). Select Distinct
          emps.Query.Distinct = true;

     (5).Select Top N
          emps.Query.Top = n;
  
     (6).Parentheses
          emps.Query.OpenParenthesis();
          emps.Query.CloseParenthesis();

     (7).GenerateSQL
        提供诊断动态查询SQL语句的功能,返回SQL语句。
         A diagnostic function that returns the SQL statement created for the dynamic query.
         After calling this you cannot load the object. Better to use LastQuery.

     (8).最后一次查询
         A string property that contains the SQL text of the most recently generated SQL statement.
 
     (9).返回Reader
         SqlDataReader reader = emps.Query.ReturnReader() as SqlDataReader;


本文转自Silent Void博客园博客,原文链接:http://www.cnblogs.com/happyhippy/archive/2006/08/30/601235.html,如需转载请自行联系原作者

相关文章
|
1月前
|
存储 JSON NoSQL
redis基本数据结构(String,Hash,Set,List,SortedSet)【学习笔记】
这篇文章是关于Redis基本数据结构的学习笔记,包括了String、Hash、Set、List和SortedSet的介绍和常用命令。文章解释了每种数据结构的特点和使用场景,并通过命令示例演示了如何在Redis中操作这些数据结构。此外,还提供了一些练习示例,帮助读者更好地理解和应用这些数据结构。
redis基本数据结构(String,Hash,Set,List,SortedSet)【学习笔记】
|
2月前
|
存储 C++
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
35 0
|
4月前
|
编译器 C++
【C++】学习笔记——string_5
【C++】学习笔记——string_5
21 0
|
4月前
|
编译器 C语言 C++
【C++】学习笔记——string_4
【C++】学习笔记——string_4
25 0
|
4月前
|
C语言 C++
【C++】学习笔记——string_3
【C++】学习笔记——string_3
24 0
|
4月前
|
存储 编译器 C++
【C++】学习笔记——string_2
【C++】学习笔记——string_2
27 0
|
4月前
|
算法 C++ 容器
【C++】学习笔记——string_1
【C++】学习笔记——string_1
26 0
|
5月前
|
Java Redis
redis-学习笔记(Jedis string 简单命令)
redis-学习笔记(Jedis string 简单命令)
39 2
|
5月前
|
NoSQL Java Redis
redis-学习笔记(string , hash , list , set , zset 前置知识)
redis-学习笔记(string , hash , list , set , zset 前置知识)
30 0
redis-学习笔记(string , hash , list , set , zset 前置知识)
|
5月前
|
存储 NoSQL Java
redis-学习笔记(string)
redis-学习笔记(string)
34 0