开发者

Dynamic Linq query on Datatable

I want to make the following query dynamic.

var t = from r in dt.AsEnumerable()  
orderby r.Field< int >("id") ascending
select r;

void query(string sorttype,string sortorder)

Is it possbile to change the order by part so that those paramater will come from parameters of a function like so开发者_运维问答rttype for id in here and sortorder for ascending.


I think this ought to do it:

IEnumerable query<sorttype>(DataTable dt, string sortorder) {
    return dt.GetList().OrderBy(row => row.Field<sorttype>(sortorder));
}

Note that sorttype is a generic type parameter, not a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜