Martin
Martin

Reputation: 24318

NHibernate: Converting an IQUERY to a dataset?

Is it possible to convert an IQuery that is returned from Nhibernate to a dataset?

I have managed to get the data to an ILIST (collection of hashtables) but how do i get it converted into a dataset?

Thanks in advance

Upvotes: 0

Views: 1038

Answers (1)

Nelson Miranda
Nelson Miranda

Reputation: 5554

I found this on google, check all the code:

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;

Upvotes: 3

Related Questions