{"id":436007,"date":"2024-10-19T15:01:11","date_gmt":"2024-10-19T15:01:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=436007"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=436007","title":{"rendered":"<span>\u0413\u0438\u0431\u043a\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f EFCore \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Expression<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>    \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 EntityFramework \u2014 \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>Where()<\/code> \u0432 LINQ. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0443\u044e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0443\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0443\u0437\u043e\u0432\u0441\u043a\u0438\u0445 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0430\u0431\u043e\u0442, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043d\u0438\u0433\u0438 \u043f\u043e \u0433\u043e\u0434\u0443 \u0438\u0437\u0434\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<pre><code class=\"cs\">var filteredBooks = await context.Books.Where(x =&gt; x.Year == 2024);<\/code><\/pre>\n<p>    \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u043f\u043e\u043a\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430. \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043d\u0438\u0433\u0438 \u0441 nullable-\u043f\u043e\u043b\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044f\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>    \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 \u043e\u0442 \u0438\u0437\u0434\u0430\u0442\u0435\u043b\u044f X, \u0438\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0433\u043e\u0434 Y \u0438 \u0436\u0430\u043d\u0440\u0430 Z. \u0422\u043e\u0433\u0434\u0430 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 JSON:<\/p>\n<pre><code class=\"json\">\"filter\": {   \"publisherId\": X,   \"year\": Y,   \"genreId\": Z }<\/code><\/pre>\n<p>    \u041f\u0440\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u044d\u0442\u043e\u0433\u043e JSON, \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code>. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cs\">var query = context.Books; if (request.Filter.Year != null)     query = query.Where(x =&gt; x.Year == request.Filter.Year); if (request.Filter.PublisherId != null)     query = query.Where(x =&gt; x.PublisherId == request.Filter.PublisherId); if (request.Filter.GenreId != null)     query = query.Where(x =&gt; x.GenreId == request.Filter.GenreId);<\/code><\/pre>\n<p>    \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c\u0441\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p>    \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>IQueryable<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>Where()<\/code> \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Expression<\/code>. \u041a\u0441\u0442\u0430\u0442\u0438 \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043b\u044f\u043c\u0431\u0434\u0443, \u043e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0433 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<h2>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Expression<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435<\/p>\n<pre><code class=\"json\">{   \"filters\": [     { \"propName\": \"Year\", \"value\": \"2024\" },     { \"propName\": \"PublisherId\", \"value\": \"1234\" },     { \"propName\": \"GenreId\", \"value\": \"1234\" }   ] }<\/code><\/pre>\n<p> \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>Where()<\/code>. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;         var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();         var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             member = Expression.Property(param, propertyName);         }         catch (ArgumentException)         {             continue;         }          IConstantExpressionHandler handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new GuidConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };                  var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }         return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); }<\/code><\/pre>\n<p> \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>IConstantExpression Handler<\/code>, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434  <code>Handle(string value)<\/code><br \/>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 <code>ConstantExpression<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: <\/p>\n<pre><code class=\"cs\">public class IntegerConstantExpressionHandler : IConstantExpressionHandler {     public ConstantExpression Handle(string value)     {         if (int.TryParse(value, out var number))             return Expression.Constant(number);         else             throw new ArgumentException(nameof(value));     } }<\/code><\/pre>\n<h2> \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f  <\/h2>\n<p> \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u043b\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u0433\u043e\u0434\u0430\u043c 2023 \u0438 2024? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0447\u0435\u0440\u0435\u0437 <code>Expression.OrElse<\/code>:  <\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;      var filtersMap = new Dictionary&lt;string, List&lt;Expression&gt;&gt;();     var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();                  if (!filtersMap.ContainsKey(propertyName))             filtersMap.Add(propertyName, new List&lt;Expression&gt;());          var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             member = Expression.Property(param, propertyName);         }         catch (ArgumentException)         {             continue;         }          var handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new GuidConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };          var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         filtersMap[propertyName].Add(expression);     }      foreach (var prop in filtersMap)     {         var expression = prop.Value.Aggregate((acc, x) =&gt; Expression.OrElse(acc, x));         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }      return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); } <\/code><\/pre>\n<h2> \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u043c \u043f\u043e\u043b\u044f\u043c  <\/h2>\n<p>\u0422\u0430 \u0447\u0430\u0441\u0442\u044c, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438 \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f. \u041c\u043d\u043e\u0433\u0438\u043c \u0438 \u0442\u0430\u043a \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 Expression, \u043e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435) \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043f\u0440\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0411\u0414, \u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 DTO. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u0434\u043e\u043c\u0435\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u044d\u0442\u043e\u0439 \u043a\u043d\u0438\u0433\u0438. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0443 \u043a\u043d\u0438\u0433\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438<\/p>\n<ul>\n<li>\n<p>\u041d\u043e\u0432\u0430\u044f &#8212; 1<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0434\u0430\u043d\u0430 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e &#8212; 2<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0430 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u043c &#8212; 3<\/p>\n<\/li>\n<li>\n<p>\u0423\u0442\u0435\u0440\u044f\u043d\u0430 &#8212; 4<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u0431\u0438\u043b\u0434\u0435\u0440 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043c\u043e\u0433 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043d\u0438\u0433\u0438, \u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b EFCore \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0411\u0414 &#8212; \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c. \u041d\u0443 \u0438 \u043a\u0430\u043a\u0438\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u0438\u043b\u0434\u0435\u0440\u0443 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 &#8212; \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0435. \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043d\u0438\u0433\u0438. <\/p>\n<pre><code class=\"cs\">[ComputedField] public static Expression&lt;Func&lt;Book, int&gt;&gt; StateId =&gt; x =&gt;     x.History != null &amp;&amp; x.History.Any()         ? x.History.OrderByDescending(h =&gt; h.WhenChanged).FirstOrDefault().StateId         : 1;<\/code><\/pre>\n<p><code>ComputedField<\/code> \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0448\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043d\u0438\u0433\u0438. \u0417\u043d\u0430\u0447\u0438\u0442 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0438 \u043d\u0430\u0448 \u0431\u0438\u043b\u0434\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;      var filtersMap = new Dictionary&lt;string, List&lt;Expression&gt;&gt;();     var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();                  if (!filtersMap.ContainsKey(propertyName))             filtersMap.Add(propertyName, new List&lt;Expression&gt;());          var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             if (Attribute.IsDefined(prop, typeof(ComputedFieldAttribute)))             {                 var computedExpression = prop.GetValue(null) as LambdaExpression;                 member = Expression.Invoke(computedExpression, param);             }             else             {                 member = Expression.Property(param, propertyName);             }         }         catch (ArgumentException)         {             continue;         }          AbstractConstantExpressionHandler handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new Base64ConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };          var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         filtersMap[propertyName].Add(expression);     }      foreach (var prop in filtersMap)     {         var expression = prop.Value.Aggregate((acc, x) =&gt; Expression.OrElse(acc, x));         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }      return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 EFCore, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0442\u0430\u043a \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435, \u0430 \u0435\u0449\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0435\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Generic \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<br \/>\u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0442\u0435\u043c\u0443 Expression \u0432 C# \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438<\/p>\n<div class=\"embed_link embed_layout-right\">\n<div class=\"embed__thumb\" style=\"background-image: url(&quot;https:\/\/habr.com\/share\/publication\/321644\/a47acd2c4594611ca05120c8ae274caf\/&quot;);\"><\/div>\n<div class=\"embed__caption\">\n<div class=\"embed__caption-title\"><span>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414<\/span><\/div>\n<div class=\"embed__caption-description\">\u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432 StackOverflow . \u041d\u0430\u0447\u043d\u0443 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f. \u0415\u0441\u0442\u044c &#8230;<\/div>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/321644\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" class=\"embed__caption-link\">habr.com<\/a><\/div>\n<\/div>\n<div class=\"embed_link embed_layout-right\">\n<div class=\"embed__thumb\" style=\"background-image: url(&quot;https:\/\/habr.com\/share\/publication\/83169\/ec468ba7b5d6ff38639958a6b5091541\/&quot;);\"><\/div>\n<div class=\"embed__caption\">\n<div class=\"embed__caption-title\"><span>Expressions \u0432 C# \u2014 impress yourself!<\/span><\/div>\n<div class=\"embed__caption-description\">.NET 4.0 \u0443\u0436\u0435 \u043d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u043a\u0443\u0447\u0443 \u0432\u0441\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c, \u043a\u0440\u0443\u0442\u043e\u0433\u043e \u0438 \u0441\u0443\u043f\u0435\u0440\u043a\u0440\u0443\u0442\u043e\u0433\u043e. &#8230;<\/div>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/83169\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" class=\"embed__caption-link\">habr.com<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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:\/\/habr.com\/ru\/articles\/851874\/\"> https:\/\/habr.com\/ru\/articles\/851874\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>    \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 EntityFramework \u2014 \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>Where()<\/code> \u0432 LINQ. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0443\u044e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0443\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0443\u0437\u043e\u0432\u0441\u043a\u0438\u0445 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0430\u0431\u043e\u0442, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043d\u0438\u0433\u0438 \u043f\u043e \u0433\u043e\u0434\u0443 \u0438\u0437\u0434\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<pre><code class=\"cs\">var filteredBooks = await context.Books.Where(x =&gt; x.Year == 2024);<\/code><\/pre>\n<p>    \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u043f\u043e\u043a\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430. \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043d\u0438\u0433\u0438 \u0441 nullable-\u043f\u043e\u043b\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044f\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>    \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 \u043e\u0442 \u0438\u0437\u0434\u0430\u0442\u0435\u043b\u044f X, \u0438\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0433\u043e\u0434 Y \u0438 \u0436\u0430\u043d\u0440\u0430 Z. \u0422\u043e\u0433\u0434\u0430 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 JSON:<\/p>\n<pre><code class=\"json\">\"filter\": {   \"publisherId\": X,   \"year\": Y,   \"genreId\": Z }<\/code><\/pre>\n<p>    \u041f\u0440\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u044d\u0442\u043e\u0433\u043e JSON, \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code>. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cs\">var query = context.Books; if (request.Filter.Year != null)     query = query.Where(x =&gt; x.Year == request.Filter.Year); if (request.Filter.PublisherId != null)     query = query.Where(x =&gt; x.PublisherId == request.Filter.PublisherId); if (request.Filter.GenreId != null)     query = query.Where(x =&gt; x.GenreId == request.Filter.GenreId);<\/code><\/pre>\n<p>    \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c\u0441\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p>    \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>IQueryable<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>Where()<\/code> \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Expression<\/code>. \u041a\u0441\u0442\u0430\u0442\u0438 \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043b\u044f\u043c\u0431\u0434\u0443, \u043e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0433 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<h2>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Expression<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435<\/p>\n<pre><code class=\"json\">{   \"filters\": [     { \"propName\": \"Year\", \"value\": \"2024\" },     { \"propName\": \"PublisherId\", \"value\": \"1234\" },     { \"propName\": \"GenreId\", \"value\": \"1234\" }   ] }<\/code><\/pre>\n<p> \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>Where()<\/code>. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;         var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();         var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             member = Expression.Property(param, propertyName);         }         catch (ArgumentException)         {             continue;         }          IConstantExpressionHandler handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new GuidConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };                  var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }         return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); }<\/code><\/pre>\n<p> \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>IConstantExpression Handler<\/code>, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434  <code>Handle(string value)<\/code><br \/>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 <code>ConstantExpression<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: <\/p>\n<pre><code class=\"cs\">public class IntegerConstantExpressionHandler : IConstantExpressionHandler {     public ConstantExpression Handle(string value)     {         if (int.TryParse(value, out var number))             return Expression.Constant(number);         else             throw new ArgumentException(nameof(value));     } }<\/code><\/pre>\n<h2> \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f  <\/h2>\n<p> \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u043b\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u0433\u043e\u0434\u0430\u043c 2023 \u0438 2024? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0447\u0435\u0440\u0435\u0437 <code>Expression.OrElse<\/code>:  <\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;      var filtersMap = new Dictionary&lt;string, List&lt;Expression&gt;&gt;();     var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();                  if (!filtersMap.ContainsKey(propertyName))             filtersMap.Add(propertyName, new List&lt;Expression&gt;());          var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             member = Expression.Property(param, propertyName);         }         catch (ArgumentException)         {             continue;         }          var handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new GuidConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };          var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         filtersMap[propertyName].Add(expression);     }      foreach (var prop in filtersMap)     {         var expression = prop.Value.Aggregate((acc, x) =&gt; Expression.OrElse(acc, x));         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }      return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); } <\/code><\/pre>\n<h2> \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u043c \u043f\u043e\u043b\u044f\u043c  <\/h2>\n<p>\u0422\u0430 \u0447\u0430\u0441\u0442\u044c, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438 \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f. \u041c\u043d\u043e\u0433\u0438\u043c \u0438 \u0442\u0430\u043a \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 Expression, \u043e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435) \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043f\u0440\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0411\u0414, \u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 DTO. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u0434\u043e\u043c\u0435\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u044d\u0442\u043e\u0439 \u043a\u043d\u0438\u0433\u0438. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0443 \u043a\u043d\u0438\u0433\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438<\/p>\n<ul>\n<li>\n<p>\u041d\u043e\u0432\u0430\u044f &#8212; 1<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0434\u0430\u043d\u0430 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e &#8212; 2<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0430 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u043c &#8212; 3<\/p>\n<\/li>\n<li>\n<p>\u0423\u0442\u0435\u0440\u044f\u043d\u0430 &#8212; 4<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u0431\u0438\u043b\u0434\u0435\u0440 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043c\u043e\u0433 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043d\u0438\u0433\u0438, \u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b EFCore \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0411\u0414 &#8212; \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c. \u041d\u0443 \u0438 \u043a\u0430\u043a\u0438\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u0438\u043b\u0434\u0435\u0440\u0443 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 &#8212; \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0435. \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043d\u0438\u0433\u0438. <\/p>\n<pre><code class=\"cs\">[ComputedField] public static Expression&lt;Func&lt;Book, int&gt;&gt; StateId =&gt; x =&gt;     x.History != null &amp;&amp; x.History.Any()         ? x.History.OrderByDescending(h =&gt; h.WhenChanged).FirstOrDefault().StateId         : 1;<\/code><\/pre>\n<p><code>ComputedField<\/code> \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0448\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043d\u0438\u0433\u0438. \u0417\u043d\u0430\u0447\u0438\u0442 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0438 \u043d\u0430\u0448 \u0431\u0438\u043b\u0434\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<pre><code class=\"cs\">public Expression&lt;Func&lt;T, bool&gt;&gt; ParseToExpression&lt;T&gt;(IEnumerable&lt;FilterField&gt; filters) {     if (filters?.Any() != true)         return x =&gt; true;      var filtersMap = new Dictionary&lt;string, List&lt;Expression&gt;&gt;();     var param = Expression.Parameter(typeof(T), \"x\");     Expression? expressionBody = null;      foreach (var filter in filters)     {         var propertyName = filter.PropertyName.FirstCharToUpper();                  if (!filtersMap.ContainsKey(propertyName))             filtersMap.Add(propertyName, new List&lt;Expression&gt;());          var prop = typeof(T).GetProperty(propertyName);         var propType = prop?.PropertyType;         Expression member;          try         {             if (Attribute.IsDefined(prop, typeof(ComputedFieldAttribute)))             {                 var computedExpression = prop.GetValue(null) as LambdaExpression;                 member = Expression.Invoke(computedExpression, param);             }             else             {                 member = Expression.Property(param, propertyName);             }         }         catch (ArgumentException)         {             continue;         }          AbstractConstantExpressionHandler handler = propType switch         {             _ when propType == typeof(Guid) =&gt; new Base64ConstantExpressionHandler(),             _ when propType == typeof(int) =&gt; new IntegerConstantExpressionHandler(),             _ when propType == typeof(string) =&gt; new StringConstantExpressionHandler(),             _ =&gt; throw new ArgumentOutOfRangeException()         };          var constant = handler.Handle(filter.Value);         var expression = Expression.Equal(member, constant);         filtersMap[propertyName].Add(expression);     }      foreach (var prop in filtersMap)     {         var expression = prop.Value.Aggregate((acc, x) =&gt; Expression.OrElse(acc, x));         expressionBody = expressionBody == null ? expression : Expression.AndAlso(expressionBody, expression);     }      return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expressionBody, param); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 EFCore, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0442\u0430\u043a \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435, \u0430 \u0435\u0449\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0435\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Generic \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<br \/>\u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-436007","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/436007","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=436007"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/436007\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=436007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=436007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=436007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}