1. hql returns ilist and combines it into a able.
String hql = "from item I left join I. Products P left join P. failuremodes F"
+ "Where P. productname =? ";
Castle. activerecord. Queries. simplequery query =
New Castle. activerecord. Queries. simplequery (typeof (item), typeof (ilist), hql, "AA ");
Ilist item = (ilist) Castle. activerecord. activerecordbase. executequery (query );
//// The specific field to be queried, which must be passed in dynamically
Private datatable maketable (ilist fields, ilist item)
{
Datatable table = new datatable ("data ");
Datacolumn column = NULL;
Foreach (queryfield field in fields)
{
Column = new datacolumn ();
Column. datatype = system. type. GetType ("system. String ");
Column. Caption = field. displaytext;
Column. columnname = field. displaytext;
Table. Columns. Add (column );
}
Datarow row;
Foreach (object [] ol in item)
{
Row = table. newrow ();
Int J = 0;
Foreach (Object o in Ol)
{
Row [Table. Columns [J] = O;
J ++;
}
Table. Rows. Add (ROW );
}
Return table;
}
2. Return datatable using SQL statements
String ssql = "select I. itemname, P. productname, F. failurename"
+ "From item I left join product P on I. Itemid = P. Itemid"
+ "Left join failuremode F on p. productid = f. productid"
+ "Where P. productname = 'A '";
Castle. activerecord. framework. isessionfactoryholder sessionholder =
Castle. activerecord. activerecordmediator. getsessionfactoryholder ();
nhib.pdf. isession session = sessionholder. createsession (typeof (item);
try
{< br> idbcommand command = session. connection. createcommand ();
command. commandtext = ssql;
idatareader RDR = command. executereader ();
datatable dt = new datatable ();
DT. load (RDR, loadoption. upsert);
Datagridview1.datasource = DT;
}
Finally
{
Sessionholder. releasesession (session );
}
3. Public static ilist <t> getdatasource <t> (Project curproject)
{
Try
{
Type T = typeof (t );
If (t = NULL) return NULL;
Parameterexpression Param = expression. parameter (T, "TT ");
// C. City = "London"
Expression left = expression. Property (Param, T. getproperty ("project "));
Expression right = expression. Constant (curproject );
Expression Filter = expression. Equal (left, right );
Expression Pred = expression. Lambda (filter, Param );
// Where (C => C. City = "London ")
Iqueryable <t> query = from TT in activerecordlinq. asqueryable <t> ()
Select tt;
Expression expr = expression. Call (
Typeof (queryable ),
"Where ",
New Type [] {t },
Expression. Constant (query ),
PRED
);
VaR ls = query. tolist <t> (). asqueryable <t> (). provider. createquery <t> (expr );
Return ls. tolist <t> ();
}
Catch
{
Return NULL;
}
}