LINQ Query Provider

The C# client library contains a LINQ Query provider that allows the developer to use LINQ to perform queries vs core. This provider wraps the Find method of a specific service. (for example the IVaultService_Find method is used by Query<Vault>).

To use the LINQ syntax you invoke the Query method of the Client.

Not all LINQ queries can be translated to server calls, so any LINQ queries that are not supported will be executed on the client after the server call has been made. This can cause some side effects in special cases.

The LINQ query (or translatable parts) is converted to a Query, Filter and PopulateQuery instances (like the VaultQuery, VaultFilter and VaultPopulationQuery types). So to write

var vaults = client.Query<Vault>().Where(v => v.CurrentUserRole == VaultRoles.Contribute)
    .Include(v => v.AccessList).Include(v => v.MetadataDefinitions).ToList();

is just a shorthand version of

var vaultService = client.CreateChannel<IVaultService>();
var query = new VaultQuery {
    Filter = { UserMinAccess = VaultRoles.Contribute, Take = 10, Skip = 10 },
    Populate = { AccessList = true, MetadataDefinitions = true }
var vaults = vaultService.Find(query);


  • When invoking Skip/Take all trailing LINQ statements will be executed locally (not be passed to the server). If performance is slow, see to your LINQ expressions so that filtering and ordering are done before Skip/Take if possible.
  • Not all LINQ filters are translated to server filters.
  • Order of server filters are ignored
  • InvalidQueryException can be the result when trying to do unsupported combinations (like server side Skip/Take in combination with local sorting)
comments powered by Disqus
+46 (0)480 - 31 47 95
English website