I am looking for code samples to mock dataset after stored proc call using Subsonic.
Here is my method.
public List<DistributionDetail> GetDistributionsForInvoice(string invoiceId)
{
List<DistributionDetail> result = new List<DistributionDetail>();
StoredProcedure sp = new StoredProcedure("GetDistributions", this.dataProvider);
sp.Command.AddParameter("InvoiceID", invoiceId, DbType.String, ParameterDirection.Input);
DataTable dt = sp.ExecuteDataSet().Tables[0];
foreach (DataRow dr in dt.Rows)
开发者_运维知识库 {
DistributionDetail d = new DistributionDetail();
DateTime date = Convert.ToDateTime(dr[2].ToString());
d.DistributionId = dr[0].ToString();
d.DistributionAmount = Convert.ToDouble(dr[1].ToString());
d.DepositDate = date.ToString(ApplicationConstants.DateFormat);
d.LockboxNumber = dr[3].ToString();
d.BatchNumber = dr[4].ToString();
d.TransactionNumber = dr[5].ToString();
result.Add(d);
}
return result;
}
In SubSonic 2.2, you can call ExecuteTypedList.
public List<DistributionDetail> GetDistributionsForInvoice(string invoiceId)
{
List<DistributionDetail> result = new List<DistributionDetail>();
StoredProcedure sp = new StoredProcedure("GetDistributions", this.dataProvider);
sp.Command.AddParameter("InvoiceID", invoiceId, DbType.String, ParameterDirection.Input);
return sp.ExecuteTypedList<DistributionDetail>();
}
The column names from the stored procedure result set must match the property names on DistributionDetail.
精彩评论