Conversion MethodCode:
Code Private Datatable converttotable (iqueryable query)
{
Datatable dtlist = New Datatable ();
Bool Isadd = False ;
Propertyinfo [] objproterties = Null ;
Foreach (VAR item In Query)
{
If ( ! Isadd)
{
Objproterties = Item. GetType (). getproperties ();
Foreach (VAR itemproterty In Objproterties)
{
Type type = Null ;
If (Itemproterty. propertytype ! = Typeof ( String ) && Itemproterty. propertytype ! = Typeof ( Int ) && Itemproterty. propertytype ! = Typeof (Datetime ))
{
Type = Typeof ( String );
}
Else
{
Type = Itemproterty. propertytype;
}
Dtlist. Columns. Add (itemproterty. Name, type );
}
Isadd = True ;
}
VaR row = Dtlist. newrow ();
Foreach (VAR pi In Objproterties)
{
Row [Pi. Name] = Pi. getvalue (item, Null );
}
Dtlist. Rows. Add (ROW );
}
ReturnDtlist;
}
Call method:
// LINQ query statement
VaR querydata =
From dv In Emcsdatacontext. dailyvals
Join VRB In Emcsdatacontext. Variables on DV. variableid equals VRB. variableid
Where DV. variableid = Variableid && DV. collecttime > = SelectDate && DV. collecttime < SelectDate. adddays ( 1 )
Orderby DV. collecttime
Select New
{
DV. ID,
DV. variableid,
DV. collecttime,
DV. variablevalue,
VRB. uplimite,
VRB. lowlimite,
Statdate = DV. collecttime. tow.timestring ()
};
// Conversion
Converttotable (Querydata)