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

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

     毕业刚半年,接触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很笼统很浅显的介绍,下篇我想举些例子来运用下以上的方法,元宵节快乐!

 

 

posted on 2009-02-09 22:21  Pavel Yu  阅读(2192)  评论(0编辑  收藏  举报