我正在寻找使用Subsonic存储过程调用后模拟数据集的代码示例。
这是我的方法。
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;
}
答案 0 :(得分:0)
在SubSonic 2.2中,您可以拨打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>();
}
存储过程结果集中的列名必须与DistributionDetail上的属性名匹配。