8 Kasım 2020 Pazar

QueryParamsModel

using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Model.Model { public class QueryParamsModel { public string Filter { get; set; } public string SortOrder { get; set; } public string SortField { get; set; } public int PageSize { get; set; } public int PageNumber { get; set; } public IQueryable Sort(IQueryable query) { if (!string.IsNullOrEmpty(this.SortField)) { var entityType = typeof(T); var property = entityType .GetProperties() .FirstOrDefault(c => c.Name.ToLowerInvariant() == this.SortField.ToLowerInvariant()); if (property != null) { var parameterExp = Expression.Parameter(entityType); var memberExp = Expression.MakeMemberAccess(parameterExp, property); var bodyExp = Expression.Convert(memberExp, typeof(object)); var lambdaExp = Expression.Lambda>(bodyExp, parameterExp); if (this.SortOrder == "desc") { query = query.OrderByDescending(lambdaExp); } else { query = query.OrderBy(lambdaExp); } } } return query; } } }

Hiç yorum yok:

Yorum Gönder

.net 6 mapget kullanımı

 app.UseEndpoints(endpoints => {     endpoints.MapGet("/", async context =>     {         var response = JsonConvert.Seriali...