是否可以将从Nhibernate返回的IQuery转换为数据集?
我已经设法将数据提供给ILIST(哈希表的集合)但是如何将其转换为数据集?
提前致谢
答案 0 :(得分:3)
我在google上找到this,检查所有代码:
DataTable dt = new DataTable();
dt.Columns.Add("CustomerId", typeof(int));
dt.Columns.Add("CustomerName", typeof(string));
dt.Columns.Add("RegisteredAt", typeof(string));//not a typo, sadly.
// ... lot more properties, often nested ones.
foreach(Customer cust in customers)
{
DataRow row = dt.NewRow();
row["CustomerId"] = cust.Id;
row["CustomerName"] = cust.At(reportDate).Name;
row["RegisteredAt"] = cust.RegisteredAt.ToShortDateString();
//... lot more properties
dt.Rows.Add(row);
}
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds;