Index > ExpressionPowerTools.Serialization.EFCore.Http > ExpressionPowerTools.Serialization.EFCore.Http.Extensions > ClientExtensions
Client extensions for remote queries.
public static class ClientExtensionsInheritance Object → ClientExtensions
The first step is to register the client. The client uses IHttpClientFactory to register a typed instance of IRemoteQueryClient for processing. This requires a base address to make calls.
builder.Services.AddExpressionPowerToolsEFCore(new Uri(builder.HostEnvironment.BaseAddress));
This is typically done in the Program.cs for Blazor WebAssembly. It should be part of initialization as it
configures the internal dependency injection service ( ServiceHost ). You must have a reference to the DbContext (it is used for the shape of the query and never run on the client). Use the DbClientContext<TContext> to start your query by referencing a root collection to use.
var query = DbClientContext<ThingContext>.Query(context => context.Things)
.Where(t => t.IsActive == ActiveFlag &&
EF.Functions.Like(t.Name, $"%{nameFilter}%"))
.OrderBy(t => EF.Property<DateTime>(t, nameof(Thing.Created)));
When you are ready to execute the query remotely, use the ExecuteRemote extension
and specify the collection type, a single item, or count.
var result = await query.ExecuteRemote().ToListAsync();
There are a few steps involved to run and resolve a remote query. See examples for more information.
| Method | Description |
|---|---|
| Void AddExpressionPowerToolsEFCore(IServiceCollection collection, Uri baseAddress, Action<IClientHttpConfiguration> configure) | Adds the client and provides the opportunity to configure it. |
| Task<IEnumerable<T>> AsEnumerableAsync<T>(IRemoteQueryable<T> query) | Grabs the enumerable. |
| IQueryable<T> AsRemoteQueryable<T>(IEnumerable<T> source, RemoteContext context) | Takes an enumerable and builds a host for remote processing. |
| Task<Int32> CountAsync<T>(IRemoteQueryable<T> query) | Provides a count of the query. |
| IRemoteQueryable<T> ExecuteRemote<T>(IQueryable<T> query) | Use this to indicate you are about to run a remote query. |
| Task<T> FirstOrSingleAsync<T>(IRemoteQueryable<T> query) | Grabs the first item, or the single item, from the result. |
| Task<T[]> ToArrayAsync<T>(IRemoteQueryable<T> query) | Grabs the array. |
| Task<HashSet<T>> ToHashSetAsync<T>(IRemoteQueryable<T> query) | Grabs the hash set. |
| Task<List<T>> ToListAsync<T>(IRemoteQueryable<T> query) | Grabs the list. |
| Generated | Copyright | Version |
|---|---|---|
| 02/22/2021 21:59:57 | (c) Copyright 2020 Jeremy Likness. | 0.9.7-beta |