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
總結
以上是生活随笔為你收集整理的SubSonic学习(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网易云音乐自建服务器,自建私有云音乐服务
- 下一篇: DB2 错误码sqlcode对应表