首页 新闻 赞助 找找看

Dynamic Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> Expression 解析成SQL

0
悬赏园豆:100 [待解决问题]

例如:

Func<IQueryable<Customers>, IOrderedQueryable<Customers>> orderBy = o => o.OrderBy(c => c.CustomerId).OrderByDescending(c => c.Level);

 

解析成

 

string sql = "order by CustomerId, Level desc";

Chris_Mo的主页 Chris_Mo | 初学一级 | 园豆:102
提问于:2015-07-27 09:04
< >
分享
所有回答(2)
1

用OrderBy..ThenBy:

.OrderByDescending(c => c.CustomerId)
.ThenByDescending(c => c.Level)
dudu | 园豆:31075 (高人七级) | 2015-07-27 09:54
0

可以把所以的条件链接起来,应该也行

public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> exprLeft,
Expression<Func<T, bool>> exprRight)
{
var invokedExpr = Expression.Invoke(exprRight, exprLeft.Parameters);
return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(exprLeft.Body, invokedExpr), exprLeft.Parameters);

}

稳稳的河 | 园豆:4216 (老鸟四级) | 2015-07-27 17:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册