Sm.EntityFrameworkCore.SimpleSort
1.0.2
dotnet add package Sm.EntityFrameworkCore.SimpleSort --version 1.0.2
NuGet\Install-Package Sm.EntityFrameworkCore.SimpleSort -Version 1.0.2
<PackageReference Include="Sm.EntityFrameworkCore.SimpleSort" Version="1.0.2" />
<PackageVersion Include="Sm.EntityFrameworkCore.SimpleSort" Version="1.0.2" />
<PackageReference Include="Sm.EntityFrameworkCore.SimpleSort" />
paket add Sm.EntityFrameworkCore.SimpleSort --version 1.0.2
#r "nuget: Sm.EntityFrameworkCore.SimpleSort, 1.0.2"
#:package Sm.EntityFrameworkCore.SimpleSort@1.0.2
#addin nuget:?package=Sm.EntityFrameworkCore.SimpleSort&version=1.0.2
#tool nuget:?package=Sm.EntityFrameworkCore.SimpleSort&version=1.0.2
EfSimpleSort
EfSimpleSort
is a simple Entity Framework Core and Clean Architecture
extension for domain models. It provides sorting capabilities using a source
generator to automatically generate sorting methods based on domain model
properties.
Features
- Automatically generates sorting methods for your entity models.
- Supports sorting based on multiple properties of the model.
- Built with Clean Architecture in mind.
- No runtime reflection, everything is done at compile-time through source generation.
Installation
To install the package, use the following command via NuGet Package Manager:
dotnet add package Sm.EntityFrameworkCore.SimpleSort --version 1.0.0
Or install it via the NuGet package manager in Visual Studio.
Usage
1. Basic Sorting with Source Generator
The source generator will automatically generate sorting methods for your entities. For example, if you have an entity like the following:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
The source generator will generate an extension method like this:
public static IQueryable<Product> SortBy(this IQueryable<Product> query, ISortable obj)
{
Expression<Func<Product, object>> selectedColumn = obj.SortColumn switch
{
"Id" => x => x.Id,
"Name" => x => x.Name,
"Price" => x => x.Price,
_ => x => x.Id
};
return obj.SortOrder == "desc"
? query.OrderByDescending(selectedColumn)
: query.OrderBy(selectedColumn);
}
2. Sorting with Custom Attributes
To enable sorting on specific entities, you can decorate them with the [Sortable]
attribute.
[Sortable]
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
This tells the source generator to automatically generate the sorting logic for the Product
class.
3. Sorting by Suffix
If you prefer to sort by suffix, you can name your class with a specific suffix (e.g., Sortable
). The source generator will automatically recognize this and generate the sorting methods accordingly.
public class ProductSortable
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
4. Customizable Folder-Based Sorting
You can configure the source generator to generate sorting methods for classes located in specific folders, such as Entities
.
The source generator will look for entities in the specified folders and automatically generate sorting logic.
Contributing
We welcome contributions to the project. If you'd like to contribute, feel free to open a pull request or issue on our GitHub repository.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.Analyzers (>= 3.11.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Added top-level class support for sorting