public static System.Data.DataSet CustOrderHist(NBearLite.Database db, out int RETURN_VALUE, string CustomerID)
{
if ((db == null))
{
throw new System.ArgumentNullException("db", "Parameter: db could not be null!");
}
NBearLite.StoredProcedureSection spSection = db.StoredProcedure("CustOrderHist");
System.Collections.Generic.Dictionary<string, object> outValues;
spSection.SetReturnParameter("RETURN_VALUE", System.Data.DbType.Int32, 0);
spSection.AddInputParameter("CustomerID", System.Data.DbType.StringFixedLength, CustomerID);
System.Data.DataSet ds = spSection.ToDataSet(out outValues);
RETURN_VALUE = ((int)(outValues["RETURN_VALUE"]));
return ds;
}
这样我们调用该存储过程就可以直接使用函数传参和获得返回值,完全可以避免烦杂的ADO.NET对象操作,便于调用和维护。对数据库中的每个存储过程,NBearLite都会生成一个与之对应的调用函数。
现在,参照NBearLite的Test用例,简单介绍一下NBearLite该如何使用。首先要创建一个Database对象,Database db = new Database("Northwind");该构造函数可接受多种重载,这种是最常用的重载方式,”Northwind”是在application config 中定义好的一个数据库连接串名称。
<add name="Northwind" connectionString="Server=(local);Database=Northwind;Uid=sa;Pwd=sa" /> 该配置节的providerName属性名可以用于指定使用哪种NBearLite Db Provider,如下配置节就表示,客户系统希望使用postgresql数据库:
<add name="Postgres" connectionString="User ID=postgres;Password=sasa;Host=localhost;Port=5432;Database=postgres;
Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;" providerName="postgresql" />
Database对象生成后,就所有的数据库操作都是通过它来完成的,其中Northwind类就是由NBearLite.QueryColumnsGenerator生成的数据库描述类: 1. 往数据库插入一条只有一个CategoryName字段值的记录