{"id":284209,"date":"2017-03-30T22:30:02","date_gmt":"2017-03-30T18:30:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284209"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284209","title":{"rendered":"\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 C#"},"content":{"rendered":"<p>C# \u2014 \u044f\u0437\u044b\u043a \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430\u043b\u044c\u043d\u044b\u0439. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043a\u0440\u0435\u043d \u043d\u0430\u043c\u0435\u0442\u0438\u043b\u0441\u044f \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 <a href=\"https:\/\/habrahabr.ru\/post\/280978\/\">\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u0449\u0438\u043d\u044b<\/a>. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430, \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044f\u0437\u044b\u043a \u0432 F#.<a name=\"habracut\"><\/a>  <\/p>\n<h4>PipeTo<\/h4>\n<p>  \u041f\u043e\u043a\u0430 <a href=\"https:\/\/github.com\/dotnet\/roslyn\/issues\/5445\">Pipe Operator<\/a> \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u043b\u0438\u0437. \u0427\u0442\u043e-\u0436, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u043c.  <\/p>\n<pre><code class=\"cs\">public static TResult PipeTo&lt;TSource, TResult&gt;(     this TSource source, Func&lt;TSource, TResult&gt; func)     =&gt; func(source);<\/code><\/pre>\n<p>  <b>\u0418\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/b>  <\/p>\n<pre><code class=\"cs\">public IActionResult Get() {     var someData = query         .Where(x =&gt; x.IsActive)         .OrderBy(x =&gt; x.Id)         .ToArray();     return Ok(someData); } <\/code><\/pre>\n<p>  <b>\u0421 PipeTo<\/b>  <\/p>\n<pre><code class=\"cs\">public IActionResult Get() =&gt;  query     .Where(x =&gt; x.IsActive)     .OrderBy(x =&gt; x.Id)     .ToArray()     .PipeTo(Ok);<\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043b\u0438? \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0437\u0433\u043b\u044f\u0434 \u043a \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a Ok. \u0421 PipeTo execution-flow \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043b\u0435\u0432\u0430-\u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u0441\u0432\u0435\u0440\u0445\u0443-\u0432\u043d\u0438\u0437.<\/p>\n<h4>Either<\/h4>\n<p>  \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0447\u0430\u0449\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f, \u0447\u0435\u043c \u0431\u044b\u0432\u0430\u044e\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c\u0438:  <\/p>\n<pre><code class=\"cs\">public IActionResult Get(int id) =&gt;  query     .Where(x =&gt; x.Id == id)     .SingleOrDefault()     .PipeTo(x =&gt; x != null ? Ok(x) : new NotFoundResult(\u201cNot Found\u201d));<\/code><\/pre>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e. \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>Either<\/code>:<\/p>\n<pre><code class=\"cs\">public static TOutput Either&lt;TInput, TOutput&gt;(this TInput o, Func&lt;TInput, bool&gt; condition,     Func&lt;TInput, TOutput&gt; ifTrue, Func&lt;TInput, TOutput&gt; ifFalse)     =&gt; condition(o) ? ifTrue(o) : ifFalse(o);  public IActionResult Get(int id) =&gt;  query     .Where(x =&gt; x.Id == id)     .SingleOrDefault()     .Either(x =&gt; x != null, Ok, _ =&gt; (IActionResult)new NotFoundResult(&quot;Not Found&quot;));<\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043d\u0430 null:  <\/p>\n<pre><code class=\"cs\">public static TOutput Either&lt;TInput, TOutput&gt;(this TInput o, Func&lt;TInput, TOutput&gt; ifTrue,     Func&lt;TInput, TOutput&gt; ifFalse)     =&gt; o.Either(x =&gt; x != null, ifTrue, ifFalse);  public IActionResult Get(int id) =&gt;  query     .Where(x =&gt; x.Id == id)     .SingleOrDefault()     .Either(Ok, _ =&gt; (IActionResult)new NotFoundResult(&quot;Not Found&quot;));<\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0432\u044b\u0432\u043e\u0434 \u0442\u0438\u043f\u043e\u0432 \u0432 C# \u0435\u0449\u0435 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044f\u0432\u043d\u044b\u0439 \u043a\u0430\u0441\u0442 \u043a <code>IActionResult<\/code>.<\/p>\n<h4>Do<\/h4>\n<p>  Get-\u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u00ab\u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u043e\u00bb.  <\/p>\n<pre><code class=\"cs\">public static T Do&lt;T&gt;(this T obj, Action&lt;T&gt; action) {     if (obj != null)     {         action(obj);     }      return obj; }  public IActionResult Get(int id) =&gt;  query     .Where(x =&gt; x.Id == id)     .Do(x =&gt; ViewBag.Title = x.Name)     .SingleOrDefault()     .Either(Ok, _ =&gt; (IActionResult)new NotFoundResult(&quot;Not Found&quot;));<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u0441 Do \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0440\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f code review. \u0425\u043e\u0442\u044f \u0432 \u0446\u0435\u043b\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Do \u2014 \u043e\u0447\u0435\u043d\u044c \u0441\u043f\u043e\u0440\u043d\u0430\u044f \u0438\u0434\u0435\u044f.<\/p><\/blockquote>\n<p>  <\/p>\n<h4>ById<\/h4>\n<p>  \u041d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e <code>q.Where(x =&gt; x.Id == id).SingleOrDefault()<\/code> \u043c\u0443\u0442\u043e\u0440\u043d\u043e?  <\/p>\n<pre><code class=\"cs\">public static TEntity ById&lt;TKey, TEntity&gt;(this IQueryable&lt;TEntity&gt; queryable, TKey id)     where TEntity : class, IHasId&lt;TKey&gt; where TKey : IComparable, IComparable&lt;TKey&gt;, IEquatable&lt;TKey&gt;     =&gt; queryable.SingleOrDefault(x =&gt; x.Id.Equals(id));  public IActionResult Get(int id) =&gt;  query     .ById(id)     .Do(x =&gt; ViewBag.Title = x.Name)     .Either(Ok, _ =&gt; (IActionResult)new NotFoundResult(&quot;Not Found&quot;));<\/code><\/pre>\n<p>  \u0410 \u0435\u0441\u043b\u0438, \u044f \u043d\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f:  <\/p>\n<pre><code class=\"cs\">public static TProjection ById&lt;TKey, TEntity, TProjection&gt;(this IQueryable&lt;TEntity&gt; queryable, TKey id, Expression&lt;Func&lt;TEntity, TProjection&gt;&gt; projectionExpression)     where TKey : IComparable, IComparable&lt;TKey&gt;, IEquatable&lt;TKey&gt;     where TEntity : class, IHasId&lt;TKey&gt;     where TProjection : class, IHasId&lt;TKey&gt;     =&gt; queryable.Select(projectionExpression).SingleOrDefault(x =&gt; x.Id.Equals(id));     public IActionResult Get(int id) =&gt;  query     .ById(id, x =&gt; new {Id = x.Id, Name = x.Name, Data = x.Data})     .Do(x =&gt; ViewBag.Title = x.Name)     .Either(Ok, _ =&gt; (IActionResult)new NotFoundResult(&quot;Not Found&quot;));<\/code><\/pre>\n<p>  \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 <code>(IActionResult)new NotFoundResult(&quot;Not Found&quot;))<\/code> \u0443\u0436\u0435 \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043b\u044c\u043a\u0430\u043b\u043e\u0441\u044c \u0438 \u0432\u044b \u0441\u0430\u043c\u0438 \u0431\u0435\u0437 \u0442\u0440\u0443\u0434\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 <code>OkOrNotFound<\/code><\/p>\n<h4>Paginate<\/h4>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043d\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0435\u0437 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e:  <\/p>\n<pre><code class=\"cs\">.Skip((paging.Page - 1) * paging.Take) .Take(paging.Take);<\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">public interface IPagedEnumerable&lt;out T&gt; : IEnumerable&lt;T&gt; {     long TotalCount { get; } }  public static IQueryable&lt;T&gt; Paginate&lt;T&gt;(this IOrderedQueryable&lt;T&gt; queryable, IPaging  paging)  =&gt; queryable     .Skip((paging.Page - 1) * paging.Take)     .Take(paging.Take);  public static IPagedEnumerable&lt;T&gt; ToPagedEnumerable&lt;T&gt;(this IOrderedQueryable&lt;T&gt; queryable,     IPaging paging)     where T : class     =&gt; From(queryable.Paginate(paging).ToArray(), queryable.Count());  public static IPagedEnumerable&lt;T&gt; From&lt;T&gt;(IEnumerable&lt;T&gt; inner, int totalCount)     =&gt;  new PagedEnumerable&lt;T&gt;(inner, totalCount);  public IActionResult Get(IPaging paging) =&gt;  query     .Where(x =&gt; x.IsActive)     .OrderBy(x =&gt; x.Id)     .ToPagedEnumerable(paging)     .PipeTo(Ok);<\/code><\/pre>\n<p>  <\/p>\n<h4>IQueryableSpecification<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0412\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f <a href=\"https:\/\/habrahabr.ru\/post\/325280\/\">\u0438\u0434\u0435\u044f \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c Where \u0438 OrderBy \u0432 LINQ \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445<\/a>:  <\/p>\n<pre><code class=\"cs\">public class MyNiceSpec : AutoSpec&lt;MyNiceEntity&gt; {     public int? Id { get; set; }      public string Name { get; set; }      public string Code { get; set; }      public string Description { get; set; } }  public IActionResult Get(MyNiceSpec spec) =&gt;  query     .Where(spec)     .OrderBy(spec)     .ToPagedEnumerable(paging)     .PipeTo(Ok); <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c <code>Where<\/code> \u0432\u044b\u0437\u043e\u0432\u0430 <code>Select<\/code>, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u2014 \u043f\u043e\u0441\u043b\u0435. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>MaybeWhere<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u0441 <code>IQueryableSpecification<\/code>, \u0442\u0430\u043a \u0438 \u0441 <code>Expression&lt;Func&lt;T, bool&gt;&gt;<\/code>  <\/p>\n<pre><code class=\"cs\">public static IQueryable&lt;T&gt; MaybeWhere&lt;T&gt;(this IQueryable&lt;T&gt; source, object spec)     where T : class {     var specification = spec as IQueryableSpecification&lt;T&gt;;     if (specification != null)     {         source = specification.Apply(source);     }      var expr = spec as Expression&lt;Func&lt;T, bool&gt;&gt;;     if (expr != null)     {         source = source.Where(expr);     }      return source; }<\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"cs\">public static IPagedEnumerable&lt;TDest&gt; Paged&lt;TEntity, TDest&gt;( this IQueryableProvider queryableProvider, IPaging spec , Expression&lt;Func&lt;TEntity, TDest&gt;&gt; projectionExpression)     where TEntity : class, IHasId     where TDest : class, IHasId     =&gt; queryableProvider         .Query&lt;TEntity&gt;()         .MaybeWhere(spec)         .Select(projectionExpression)         .MaybeWhere(spec)         .MaybeOrderBy(spec)         .OrderByIdIfNotOrdered()         .ToPagedEnumerable(spec);<\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/github.com\/AutoMapper\/AutoMapper\/wiki\/Queryable-Extensions\">Queryable Extensions AutoMapper<\/a>:  <\/p>\n<pre><code class=\"cs\">public static IPagedEnumerable&lt;TDest&gt; Paged&lt;TEntity, TDest&gt;(this IQueryableProvider queryableProvider,     IPaging spec)     where TEntity : class, IHasId     where TDest : class, IHasId =&gt; queryableProvider         .Query&lt;TEntity&gt;()         .MaybeWhere(spec)         .ProjectTo&lt;TDest&gt;()         .MaybeWhere(spec)         .MaybeOrderBy(spec)         .OrderByIdIfNotOrdered()         .ToPagedEnumerable(spec);<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043b\u0435\u043f\u0438\u0442\u044c <code>IPaging<\/code>, <code>IQueryableSpecififcation<\/code> \u0438 <code>IQueryableOrderBy<\/code> \u043d\u0430 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u043e\u0433\u043e\u043c\u0435\u0440\u0437\u043a\u043e, \u0442\u043e \u0432\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0442\u0430\u043a\u043e\u0439:  <\/p>\n<pre><code class=\"cs\">public static IPagedEnumerable&lt;TDest&gt; Paged&lt;TEntity, TDest&gt;(this IQueryableProvider queryableProvider,     IPaging paging, IQueryableOrderBy&lt;TDest&gt; queryableOrderBy, IQueryableSpecification&lt;TEntity&gt; entitySpec = null, IQueryableSpecification&lt;TDest&gt; destSpec = null)     where TEntity : class, IHasId where TDest : class     =&gt; queryableProvider         .Query&lt;TEntity&gt;()         .EitherOrSelf(entitySpec, x =&gt; x.Where(entitySpec))         .ProjectTo&lt;TDest&gt;()         .EitherOrSelf(destSpec, x =&gt; x.Where(destSpec))         .OrderBy(queryableOrderBy)         .ToPagedEnumerable(paging);<\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442, \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 LINQ.  <\/p>\n<pre><code class=\"cs\">public IActionResult Get(MyNiceSpec spec) =&gt;  query     .Paged&lt;int, MyNiceEntity, MyNiceDto&gt;(spec)     .PipeTo(Ok);<\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 C# \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043c\u043e\u043d\u0441\u0442\u0440\u0443\u043e\u0437\u043d\u043e \u0438\u0437-\u0437\u0430 \u043e\u0431\u0438\u043b\u0438\u044f generic&#8217;\u043e\u0432. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b extension&#8217;\u043e\u0432 LINQ \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0436\u0435. \u041a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 <code>Select<\/code> \u0442\u0438\u043f? \u0425\u0432\u0430\u043b\u0430 <code>var<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0431\u0430\u0432\u0438\u043b \u043d\u0430\u0441 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043c\u0443\u0447\u0435\u043d\u0438\u044f.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/325308\/\"> https:\/\/habrahabr.ru\/post\/325308\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# \u2014 \u044f\u0437\u044b\u043a \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430\u043b\u044c\u043d\u044b\u0439. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043a\u0440\u0435\u043d \u043d\u0430\u043c\u0435\u0442\u0438\u043b\u0441\u044f \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 <a href=\"https:\/\/habrahabr.ru\/post\/280978\/\">\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u0449\u0438\u043d\u044b<\/a>. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430, \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044f\u0437\u044b\u043a \u0432 F#.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284209","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284209"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284209\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}