SubSonic学习(一)

     月圆之夜,窗外炮竹声不绝于耳,今晚,幸福属于我们每个人!

      忽然想起一句和元宵佳节有关的诗“众里寻他千百度,蓦然回首,那人却在灯火阑珊处”。诗中的哲理蕴含在日常生活的每一个角落。

     毕业刚半年,接触SubSonic时间也不长,所以只想把自己的学习笔记整理下,望能抛砖引玉了(参考http://subsonicproject.com/)

     SubSonic: Version 2.1 (Pakala)     

     a.Create a query tool where you would be able to do 95% of all the queries you’d need, in a readable, discoverable way 

     b.Work up your DAL, not complicated and time-consuming.

      c.Very very close to SQL 

 

1.Web.config

     

//创建一个自动生成类的buildProvider

//.abp文件中指明将哪些数据库表自动生成类,表名按行列出;所有都生成时,输入*

 

2.Load an object

a)      FetchByID

//SubSonic will not work with tables that do not have a primary key

Product product = Product.FetchByID(id);  

if (product.ProductID == id)

{ // Success } else { // Not Found }

//If the object is not found, SubSonic will not throw an error.

b)       the overloaded constructor

Product product = new Product(xxxxxxxxxxxxxxxxxx);

c)     NewFromXML

Session["Product"] = product.ToXML();

product=(Product)product.NewFromXML(Session["Product"].ToString());

 

2.    Retrieving Multiple Objects

a)     FetchAll()

b)    FetchByParameter()

c)     FetchByQuery(query)

d)    Product product = new Product();

          product.SupplierID = 1;

          product.CategoryID = 1;

          GridView1.DataSource = Product.Find(product);    //基于已存在的对象查找结果

e)     Query

 

3.    Queries

a)     SubSonic.Query query = Product.CreateQuery();

          SubSonic.Query query = new SubSonic.Query(xxxxxxxxxxxx);

          query.OrderBy =SubSonic.OrderBy.Asc(xxxxxxx);

          //there is no way to order by multiple columns.

b)    query.SelectList = Product.Columns.ProductName + ", " + Product.Columns.SupplierID;

          //显示指定的字段

c)     query.addwhere()

 

4.    Stored Procedures&&Commands

a)     SubSonic.StoredProcedure sp = SPs.CustOrderHist(customerID);

          //The stored procedure can then either call Execute, ExecuteScalar, GetDataSet or GetReader to execute and return the data.

b)    string sql = query.GetSql();

          SubSonic.QueryCommand cmd = product.GetInsertCommand(xxxxxx);

          //If the querying power of SubSonic falls short for your needs, you can still use the existing functionality and extend it by accessing the commands that are being built before execution.

 以上只是SubSonic很笼统很浅显的介绍,下篇我想举些例子来运用下以上的方法,元宵节快乐!

 

 

转载于:https://www.cnblogs.com/yuxhust/archive/2009/02/09/1387065.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值