如何将 orderby 参数值传递给 Lambda 函数?

huangapple go评论76阅读模式
英文:

How to pass orderby parameter value to a lambda function?

问题

Sure, here's the translation of the code snippet you provided:

_unitOfWork.GetAll(/*请在这里传递orderBy参数*/);

Please note that I've kept the code part unchanged and only translated the comment.

英文:

I am using this pattern </br>
https://gist.github.com/pmbanugo/8456744#file-ientityrepository-cs </br>
and function is

IEnumerable&lt;T&gt; GetAll(
            Expression&lt;Func&lt;T, bool&gt;&gt; filter = null,
            Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderBy = null,
            string includeProperties = null
            );

I want to pass parametere orderBy

_unitOfWork.GetAll(/*please pass orderby paramter here*/);

答案1

得分: 1

使用命名参数仅传递 orderBy 参数与排序函数。

_unitOfWork.GetAll(orderBy: x => x.OrderByDescending(y => y.Something));
英文:

Use named arguments to only pass the orderBy argument with a sorting function.

_unitOfWork.GetAll(orderBy: x =&gt; x.OrderByDescending(y =&gt; y.Something));

huangapple
  • 本文由 发表于 2023年7月18日 14:25:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定