首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > VB.NET > 以条件驱动的数据访问方式
【标  题】:以条件驱动的数据访问方式
【关键字】:
【来  源】:http://www.cnblogs.com/henryfan/archive/2006/08/20/482023.html

以条件驱动的数据访问方式

所谓“以条件驱动”其实是自己给起名称,这种数据库访问方式和传统持久化组件的操作方式有所差别。在传统的数据访问操作中先明确操作对象然后设置相关条件;但在本文中所在地提到的访问方式是以条件为主导,就是根据你需要的情况编写条件直接在这基础上进行操作,并不需要显式借助于某个容器,所有操作所需要支持的环境在条件构成造过程中隐式创建。

看以下基于条件驱动访问数据的用例代码:

System.Collections.IList list= (DBMapping.Employees.EmployeeID==3).List();

以上代码是创建EmployeeID==0的条件并获取相关条件的雇员对象集。

当然条件模型可以相对复杂

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 ;

………………………..

基本上所有包含条件的数据操作方式都可以通过这种方式去进行数据库操作。这种操作方式是在构造组件模型中无意发现,感觉其操作方便简单因此发表布出来,感趣的朋友发表一下自己的看法。

托管异常的性能:【上一篇】
atlas学习系列之二(AutoCompleteExtender篇):【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • Java 的IO操作(文件的读,写操作)
  • [收藏]C++ Tips(12)--||和&&的语句执行顺序
  • IE7取消管理员权限 将具备防间谍软件功能
  • 这是最后一次
  • 儿童冬天多发过敏性紫癜,小儿过敏性紫癜,小儿紫癜
  • 传奇私服dbc的一些常识[推荐]
  • 一个perl写的web采集程序
  • 用Photoshop的路径来做发丝
  • 一种实时火焰效果生成算法
  • oracle分析函数
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.