The C# .NET SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
.NET - Collection.Query.Where()
Adds a new where clause to a query, which filters the data returned.
using Nitric.Sdk;
using Nitric.Sdk.Resource;
class Profile {
public string Name { get; set; }
public float Age { get; set; }
}
var profiles = Nitric.Collection<Profile>("profiles").With(
CollectionPermission.Reading, CollectionPermission.Writing, CollectionPermission.Deleting
);
var profilesQuery = profiles.Query().Where("name", "startsWith", "T");
Nitric.Run();
Parameters
- Name
field
- Required
- Required
- Type
- string
- Description
The document field to query.
- Name
operation
- Required
- Required
- Type
- string
- Description
The query operation to perform.
Valid values are:startsWith | == | != | >= | <= | > | <
.
- Name
value
- Required
- Required
- Type
- string | double | int | bool
- Description
The value to compare against.
Notes
Where clauses combined together are always considered AND
Examples
A simple query
using Nitric.Sdk;
using Nitric.Sdk.Resources;
var profiles = Nitric.Collection("profiles").With(CollectionPermission.Reading);
var profileQuery = profiles.Query().Where("firstName", "==", "Drake");
Nitric.Run();
Combining where clauses
using Nitric.Sdk;
using Nitric.Sdk.Resources;
var profiles = Nitric.Collection("profiles").With(CollectionPermission.Reading);
var profileQuery = profiles.Query()
.Where("firstName", "==", "Drake")
.Where("age", ">=", 21);
Nitric.Run();