以条件驱动的数据访问方式
2006-08-20 22:23
281 查看
所谓“以条件驱动”其实是自己给起名称,这种数据库访问方式和传统持久化组件的操作方式有所差别。在传统的数据访问操作中先明确操作对象然后设置相关条件;但在本文中所在地提到的访问方式是以条件为主导,就是根据你需要的情况编写条件直接在这基础上进行操作,并不需要显式借助于某个容器,所有操作所需要支持的环境在条件构成造过程中隐式创建。
看以下基于条件驱动访问数据的用例代码:
System.Collections.IList list= (DBMapping.Employees.EmployeeID==3).List();
以上代码是创建EmployeeID==3的条件并获取相关条件的雇员对象集。
当然条件模型可以相对复杂
list =(DBMapping.Orders.Employee ==(DBMapping.Employees.EmployeeID ==3)).List();
以上是一个简单的对象约束条件。
list =(DBMapping.Orders.OrderDate.Between(
DateTime.Parse("1997-7-1"),DateTime.Parse("1997-7-31"))
& DBMapping.Orders.EmployeeID==3).List();
条件除了可以对象数据进行查询外还可以进行其他操作:
(DBMapping.Employees.EmployeeID==3).Edit(
DBMapping.Employees.Region.Set("GuangZhou"));
更新相关条件下的字段模型信息。
(DBMapping.Employees.Region.Match("Guang")).Delete();
或者删除相关条件的数据。
(DBMapping.Employees.FirstName =="henry").Count();
统计相关条件记录数.
以下是相关映射模型结构:
public class EmployeesMapper:HFSoft.Data.Mapping.Table
{
public EmployeesMapper(string name):base(name)
{
mALL = new HFSoft.Data.Mapping.ObjectField("*",this);
mEmployeeID = new HFSoft.Data.Mapping.NumberField("EmployeeID",this);
mLastName = new HFSoft.Data.Mapping.StringField("LastName",this);
mFirstName = new HFSoft.Data.Mapping.StringField("FirstName",this);
mTitle = new HFSoft.Data.Mapping.StringField("Title",this);
mTitleOfCourtesy = new HFSoft.Data.Mapping.StringField("TitleOfCourtesy",this);
mBirthDate = new HFSoft.Data.Mapping.DateTimeField("BirthDate",this);
mHireDate = new HFSoft.Data.Mapping.DateTimeField("HireDate",this);
mAddress = new HFSoft.Data.Mapping.StringField("Address",this);
mCity = new HFSoft.Data.Mapping.StringField("City",this);
mRegion = new HFSoft.Data.Mapping.StringField("Region",this);
mPostalCode = new HFSoft.Data.Mapping.StringField("PostalCode",this);
mCountry = new HFSoft.Data.Mapping.StringField("Country",this);
mHomePhone = new HFSoft.Data.Mapping.StringField("HomePhone",this);
mExtension = new HFSoft.Data.Mapping.StringField("Extension",this);
mPhoto = new HFSoft.Data.Mapping.BytesField("Photo",this);
mNotes = new HFSoft.Data.Mapping.TextField("Notes",this);
mReportsTo = new HFSoft.Data.Mapping.NumberField("ReportsTo",this);
mPhotoPath = new HFSoft.Data.Mapping.StringField("PhotoPath",this);
}
public Employees GetByIndex(int id,HFSoft.Data.IDataSession session)
{
return (Employees)OnGetByIndex(id,session);
}
public Employees GetByIndex(int id)
{
return (Employees)OnGetByIndex(id);
}
private HFSoft.Data.Mapping.NumberField mEmployeeID ;
public HFSoft.Data.Mapping.NumberField EmployeeID
{
get
{
return mEmployeeID;
}
}
private HFSoft.Data.Mapping.StringField mLastName ;
………………………..
基本上所有包含条件的数据操作方式都可以通过这种方式去进行数据库操作。这种操作方式是在构造组件模型中无意发现,感觉其操作方便简单因此发表布出来,感趣的朋友发表一下自己的看法。
看以下基于条件驱动访问数据的用例代码:
System.Collections.IList list= (DBMapping.Employees.EmployeeID==3).List();
以上代码是创建EmployeeID==3的条件并获取相关条件的雇员对象集。
当然条件模型可以相对复杂
list =(DBMapping.Orders.Employee ==(DBMapping.Employees.EmployeeID ==3)).List();
以上是一个简单的对象约束条件。
list =(DBMapping.Orders.OrderDate.Between(
DateTime.Parse("1997-7-1"),DateTime.Parse("1997-7-31"))
& DBMapping.Orders.EmployeeID==3).List();
条件除了可以对象数据进行查询外还可以进行其他操作:
(DBMapping.Employees.EmployeeID==3).Edit(
DBMapping.Employees.Region.Set("GuangZhou"));
更新相关条件下的字段模型信息。
(DBMapping.Employees.Region.Match("Guang")).Delete();
或者删除相关条件的数据。
(DBMapping.Employees.FirstName =="henry").Count();
统计相关条件记录数.
以下是相关映射模型结构:
public class EmployeesMapper:HFSoft.Data.Mapping.Table
{
public EmployeesMapper(string name):base(name)
{
mALL = new HFSoft.Data.Mapping.ObjectField("*",this);
mEmployeeID = new HFSoft.Data.Mapping.NumberField("EmployeeID",this);
mLastName = new HFSoft.Data.Mapping.StringField("LastName",this);
mFirstName = new HFSoft.Data.Mapping.StringField("FirstName",this);
mTitle = new HFSoft.Data.Mapping.StringField("Title",this);
mTitleOfCourtesy = new HFSoft.Data.Mapping.StringField("TitleOfCourtesy",this);
mBirthDate = new HFSoft.Data.Mapping.DateTimeField("BirthDate",this);
mHireDate = new HFSoft.Data.Mapping.DateTimeField("HireDate",this);
mAddress = new HFSoft.Data.Mapping.StringField("Address",this);
mCity = new HFSoft.Data.Mapping.StringField("City",this);
mRegion = new HFSoft.Data.Mapping.StringField("Region",this);
mPostalCode = new HFSoft.Data.Mapping.StringField("PostalCode",this);
mCountry = new HFSoft.Data.Mapping.StringField("Country",this);
mHomePhone = new HFSoft.Data.Mapping.StringField("HomePhone",this);
mExtension = new HFSoft.Data.Mapping.StringField("Extension",this);
mPhoto = new HFSoft.Data.Mapping.BytesField("Photo",this);
mNotes = new HFSoft.Data.Mapping.TextField("Notes",this);
mReportsTo = new HFSoft.Data.Mapping.NumberField("ReportsTo",this);
mPhotoPath = new HFSoft.Data.Mapping.StringField("PhotoPath",this);
}
public Employees GetByIndex(int id,HFSoft.Data.IDataSession session)
{
return (Employees)OnGetByIndex(id,session);
}
public Employees GetByIndex(int id)
{
return (Employees)OnGetByIndex(id);
}
private HFSoft.Data.Mapping.NumberField mEmployeeID ;
public HFSoft.Data.Mapping.NumberField EmployeeID
{
get
{
return mEmployeeID;
}
}
private HFSoft.Data.Mapping.StringField mLastName ;
………………………..
基本上所有包含条件的数据操作方式都可以通过这种方式去进行数据库操作。这种操作方式是在构造组件模型中无意发现,感觉其操作方便简单因此发表布出来,感趣的朋友发表一下自己的看法。
相关文章推荐
- 微软企业库5.0学习笔记(三十四)数据访问模块 各种获取数据的方式
- android网络访问post方式(数据传输采用json数据流,非参数传递)
- 多个线程访问共享对象和数据的方式
- spring mvc 注解访问控制器以及接收form数据的方式,包括直接接收日期类型及对象的方法
- 两种数据访问方式:从ADO 到ADO.NET
- 数据访问......单条件查询与多条件查询
- 多个线程访问共享对象和数据的方式
- DNN的数据访问方式——合理运用模式,提高数据访问的灵活性(有修正)
- 多线程要访问共享数据的方式
- 中断方式实现发送数据串口驱动
- LinkServer--访问远程数据表三种方式
- Objective-C中通过下标的方式访问自定义数据模型中属性
- struts2 lesson one: 的action特征,三种创建方法,action接收表单数据的三种访问,读取方式
- [整理]创建JavaScript对象用闭包的方式保证内部数据不能外部所访问
- Linux设备驱动开发-linux驱动中的非阻塞访问方式
- java中内部类的创建四种情况,三种方式,及内部数据访问权限
- java基础--线程04--多个线程访问共享对象和数据的方式
- 敏感数据加密保护和数据库访问方式的测试内容
- Android应用程序访问硬件驱动(JNI方式)
- 初识ADO.net-访问数据的两种方式