XSpecification.Linq
1.0.0
dotnet add package XSpecification.Linq --version 1.0.0
NuGet\Install-Package XSpecification.Linq -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="XSpecification.Linq" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XSpecification.Linq --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XSpecification.Linq, 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 XSpecification.Linq as a Cake Addin #addin nuget:?package=XSpecification.Linq&version=1.0.0 // Install XSpecification.Linq as a Cake Tool #tool nuget:?package=XSpecification.Linq&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XSpecification is an implementation of Specification pattern for Linq and Elasticsearch
Setup
Formalize your filter
public class LinqTestFilter
{
public int Id { get; set; }
public RangeFilter<int> RangeId { get; set; }
}
Create your scpecification
public class LinqTestSpec : SpecificationBase<LinqTestModel, LinqTestFilter>
{
public LinqTestSpec(ILogger<LinqTestSpec> logger, IOptions<Options> options)
: base(logger, options)
{
HandleField(f => f.Explicit, m => m.UnmatchingProperty);
}
}
Add XSpecification to your DI in Startup.cs or Program.cs
services.AddLinqSpecification();
//or optionally disable auto property handling
services.AddLinqSpecification(o =>
{
o.DisableAutoPropertyHandling = true;
});
// add scpecification to your DI
services.AddSingleton<LinqTestSpec>();
Using in your code
// Inject from DI
var spec = serviceProvider.GetRequiredService<LinqTestSpec>();
var filter = new LinqTestFilter
{
Date = DateTime.Today,
Id = 123,
Name = "qwe",
ComplexName = new StringFilter("complex") { Contains = true },
ListDate = new[] { DateTime.Today, DateTime.Today.AddDays(1) },
ListId = new[] { 1, 2, 3 },
ListName = new[] { "a", "b", "z" },
NullableDate = DateTime.Today.AddDays(-1),
RangeDate = new RangeFilter<DateTime> { Start = DateTime.Today, End = DateTime.Today.AddDays(1) },
RangeId = new RangeFilter<int> { Start = 0, End = 5 }
};
var expression = spec.CreateFilterExpression(filter);
var data = dbcontext.Set<LinqTestModel>().Where(expression);
TODO
- Add extension points for new filter types
- Refactor Expression creation logic to Chain of responsipility
- Add Elasticsearch implementation
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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Linq.Expression.Optimizer (>= 1.0.13)
- LinqKit.Core (>= 1.2.2)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- XSpecification.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 233 | 4/19/2022 |