EntityFrameworkCore.Order
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EntityFrameworkCore.Order --version 1.0.0
NuGet\Install-Package EntityFrameworkCore.Order -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EntityFrameworkCore.Order" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.Order --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EntityFrameworkCore.Order, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EntityFrameworkCore.Order as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.Order&version=1.0.0
// Install EntityFrameworkCore.Order as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.Order&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EntityFrameworkCore.Order Nuget Package
Dependency
.Net 7
Description
This nuget package allow you to sort the list by property name. If you want to short the list by OrderBy or OrderByDescy you have to send PropertyName and Reverse parameter
Parameters
public sealed record GetAllBoomQuery(
bool IsOrderTable = false, //Optional
string ColumnName = "",
bool Reverse = false) : IRequest<List<Boom>>;
Usage
IQueryable<Boom> list = _boomRepository
.AsQueryable();
if (request.IsOrderTable) //Optional
{
list = list.RequestOrderBy(request.ColumnName, request.Reverse);
}
else
{
list = list.RequestOrderBy("CreatedDate", true);
}
return await list.ToListAsync(request.PageNumber, request.PageSize, cancellationToken);
Source Code
public static class QueryableExtensions
{
public static IOrderedQueryable<T> RequestOrderBy<T>(this IQueryable<T> source, string propertyName, bool descending)
{
// Retrieve the property by reflection.
var property = typeof(T).GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
// If the property doesn't exist, throw an exception.
if (property == null)
throw new ArgumentException($"Property '{propertyName}' not found on type '{typeof(T)}'.");
// Create the selector.
var parameter = Expression.Parameter(typeof(T));
var selector = Expression.Lambda<Func<T, object>>(Expression.Convert(Expression.Property(parameter, property), typeof(object)), parameter);
// Construct the appropriate sort method and invoke it.
var sortMethod = descending ? "OrderByDescending" : "OrderBy";
var method = typeof(Queryable).GetMethods()
.Where(x => x.Name == sortMethod && x.GetParameters().Length == 2)
.Single()
.MakeGenericMethod(typeof(T), typeof(object));
return (IOrderedQueryable<T>)method.Invoke(null, new object[] { source, selector });
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.