小编Ski*_*ner的帖子

按"字符串"名称命令LINQ

问题解决了!!!

解决方案是Linq.Dynamic

你这样做:

(from c in Context.AccountCharts 
    where c.Account_FK == account && c.Year_FK == year select c).OrderBy(order);
Run Code Online (Sandbox Code Playgroud)

您必须下载System.Linq.Dynamic.dll并将其包含在您的项目中.


有没有办法按字段名称订购linq查询.像这样:

from c in Context.AccountCharts 
    where c.Account_FK == account && c.Year_FK == year 
    orderby c["ColName"] select c;
Run Code Online (Sandbox Code Playgroud)

要么

from c in Context.AccountCharts 
    where c.Account_FK == account && c.Year_FK == year 
    orderby c.GetType().GetField("ColName") select c;
Run Code Online (Sandbox Code Playgroud)

这两个都不起作用,但我希望你知道这样做的方法.

linq string sql-order-by

6
推荐指数
1
解决办法
1405
查看次数

标签 统计

linq ×1

sql-order-by ×1

string ×1