SQL Artisan数据库访问组件功能概述

来源:互联网 发布:手机网络延迟多少正常 编辑:程序博客网 时间:2024/06/16 06:55
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

SQL Artisan现有的版已经在项目中运用,在使用的过程中得到的效果相当理想.刚接触这个组件的几个新同事通过了解已有例子,很快就能适应到项目开发过程中.组件的对象操作和编译检测大提高了编写效率,在项目中得到的效果自己也有点意想不到.

SQL Artisang下一个版本的功能主完善在表对象操作和对象映射方面;包括:表对象支持数据操作,对象继承,视图对象映射,统计对象映射等.为了让组件功能扩展更方便,把组件的数据映射方式进行重构,由原来的XML描述改成Attribute;并把相关应映射成员搬迁到HFSoft.Data.Mapping名称空间下.以下描述只是组件在新版本中具备的功能,大部分还在实现过程。

表对象的数据操作

新版本表对象(Table)由Expressions名称间搬迁到Mapping名称空间下.旧版本的表对象只支持表的关联操作功能比较单一.在功能完善后会支持数据的新增、删除、修改和查询操作。在程序中可以通过以下方式定义表和字段的对象:


Table tbl = new Table("Employees");

NumberField field = new NumberField("EmployeeID");

数据新增:


Employees.TBL.Insert(

         Employees._FirstName.Set("Fan"),

         Employees._LastName.Set("Henry"),

         Employees._BirthDate.Set(DateTime.Parse("1979-1-1"))

         );

数据修改:


Employees.TBL.Update(Employees._FirstName =="Fan",

         Employees._City.Set("GuangZhou"),

         Employees._Address.Set("TianHe"),

         Employees._Region.SetNull());

数据删除:


Employees.TBL.Delete(Employees._FirstName =="Fan");

数据查询:


System.Collections.IList lst = Orders.TBL.Where(

         Orders._OrderDate >= DateTime.Parse("1997-1-1")&

         Orders._OrderDate < DateTime.Parse("1997-8-1")

         ).SelectObject();

     foreach(Orders item in lst)

     {

         Console.WriteLine(item.OrderID);

     }

统计查询:


System.Data.DataSet ds = Orders.TBL.INNER(OrderDetails.TBL,OrderDetails._OrderID)

         .Where(Orders._OrderDate >= DateTime.Parse("1997-8-1"))

         .OrderBy(Orders._EmployeeID.DESC)

         .GroupBy(Orders._EmployeeID)

     .Select(SQLMath.Sum(OrderDetails._Quantity*OrderDetails.
_UnitPrice*(1-OrderDetails._Discount)).As("account"),Orders._EmployeeID);

     foreach(System.Data.DataRow row in ds.Tables[0].Rows)

     {

         Console.WriteLine(row["account"]);

     }


<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击