问题解决了!!!
解决方案是 Linq.Dynamic
你这样做:
(from c in Context.AccountCharts
where c.Account_FK == account && c.Year_FK == year select c).OrderBy(order);
您必须下载系统.Linq.Dynamic.dll并将其包含到您的项目中。
有没有办法按字段名称对 linq 查询进行排序。像这样:
from c in Context.AccountCharts
where c.Account_FK == account && c.Year_FK == year
orderby c["ColName"] select c;
Or
from c in Context.AccountCharts
where c.Account_FK == account && c.Year_FK == year
orderby c.GetType().GetField("ColName") select c;
这两个都不起作用,但我希望你知道一种方法来做到这一点。
我花了很多时间来解决这个问题,但没有找到比以下更好的方法:
var queryExpression;
if (c["ColName"]=="CreateDate")
queryExpression.OrderBy(x => x.CreateDate);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)