LINQ support for BCC API requests, shipped as two NuGet packages:
| Package | Use it in | Contains |
|---|---|---|
| BccCode.Linq | API clients | LINQ query provider that turns queries into API requests (BccCode.Linq.Client namespace) |
| BccCode.Linq.Server | API servers | Directus-style filter parsing, sorting and paging on IQueryable (BccCode.Linq.Server namespace) |
Neither package depends on ASP.NET Core.
- Add the package you need to a .NET project:
BccCode.Linqfor client code,BccCode.Linq.Serverfor server code (or both). - See the usage examples below.
When you implement the IApiClient interface into your API client class, you are able to run linq queries against it like this:
using BccCode.Linq;
IApiClient client = ...;
var persons = from person in client.Persons
where person.Country == "NO" // Note: Equals(person.Country, "NO") works, too
select new
{
person.Age,
person.Country
};
foreach(var person in persons)
{
// Here we interate through the query result getting
// by default per API request 100 rows/persons.
}As an input param it takes a json string in directus filter format and applies the filter on a DbSet.
using BccCode.Linq.Server;
var filter = new Filter(jsonFilter); // jsonFilter is a json string representation in a Directus Filter format
var coll = await _dbContext.Collections
.ApplyRuleFilter(filter)
.ToListAsync();Version 2.0 moved the server code out of BccCode.Linq into BccCode.Linq.Server, and dropped the
Microsoft.AspNetCore.Mvc 2.x package references that the library never used.
- Projects that only use the client (
BccCode.Linq.Client): updateBccCode.Linqto 2.x. No code changes. - Projects that use
Filter,Filter<T>,ApplyRuleFilter,ApplyApiRequestor other types inBccCode.Linq.Server: also add a reference toBccCode.Linq.Server2.x. Namespaces and type names are unchanged, so no code changes. Libraries compiled against 1.x that use these types must be recompiled, because the types now live inBccCode.Linq.Server.dll. - Projects that got
Microsoft.AspNetCore.Mvctypes (for example[FromQuery]) only throughBccCode.Linq: reference them directly, preferably with<FrameworkReference Include="Microsoft.AspNetCore.App" />. - Both packages now target net10.0 only (1.x also targeted netstandard2.1, net6.0 and net8.0). Projects on older .NET versions must upgrade to .NET 10.
- The packages no longer depend on
Newtonsoft.Jsondirectly. TheBccCode.Platform.Contractsdependency still brings it in. The client still reads custom member names from bothSystem.Text.Json.Serialization.JsonPropertyNameAttributeand Newtonsoft'sJsonPropertyAttribute. - The server code now parses filters with
System.Text.Json. The values in the dictionaries ofFilterand ofFilterDeserializationHelpers.DeserializeJsonRuleareSystem.Text.Json.JsonElementinstead of Newtonsoft tokens (JToken,JArray,JObject). Code that readsFilter.Propertiesor the result ofDeserializeJsonRuleand casts values to Newtonsoft types must be changed.
See docs/aot.md for Native AOT and trimming support.