Search Results for

    Show / Hide Table of Contents

    Class QueryMethods

    Provides methods that get translated into native Realm queries when using LINQ.

    Inheritance
    object
    QueryMethods
    Namespace: Realms
    Assembly: Realm.dll
    Syntax
    public static class QueryMethods
    Remarks

    These methods don't have implementation and are only usable in a LINQ query performed on a Realm query result - e.g. the IQueryable returned by All<T>().

    Methods

    | Edit this page View Source

    Contains(string?, string, StringComparison)

    Returns a value indicating whether a specified substring occurs within this string.

    Declaration
    public static bool Contains(string? str, string value, StringComparison comparisonType)
    Parameters
    Type Name Description
    string str

    The original string.

    string value

    The string to seek.

    StringComparison comparisonType

    One of the enumeration values that determines how this string and value are compared.

    Returns
    Type Description
    bool

    true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when str or value is null.

    ArgumentException

    Thrown when comparisonType is not a valid StringComparison value.

    | Edit this page View Source

    FullTextSearch(string?, string)

    Performs a 'simple term' Full-Text search on a string property.

    Declaration
    public static bool FullTextSearch(string? str, string terms)
    Parameters
    Type Name Description
    string str

    The string to compare against the terms.

    string terms

    The terms to look for in str.

    Returns
    Type Description
    bool

    true if the string matches the terms; false otherwise.

    Remarks

    When this method is used outside of a Realm query, a NotSupportedException will be thrown.

    Examples
    var matches = realm.All<Book>().Where(b => b.Summary.FullTextSearch("fantasy novel"));
    | Edit this page View Source

    GeoWithin(IEmbeddedObject?, GeoShapeBase)

    Checks whether geoShape contains the point represented by an embedded object.

    Declaration
    public static bool GeoWithin(IEmbeddedObject? point, GeoShapeBase geoShape)
    Parameters
    Type Name Description
    IEmbeddedObject point

    An embedded object that has the shape of a GeoJson point. It must have at least two fields - IList<double> coordinates and string type. The shape of the object will be verified at runtime.

    GeoShapeBase geoShape

    One of GeoBox, GeoCircle, or GeoPolygon representing the shape that point will be checked against.

    Returns
    Type Description
    bool

    true if point is contained in geoShape; false otherwise.

    Examples

    An example embedded object that can be used in geospatial queries is:

    public partial class MyGeoPoint : IEmbeddedObject
    {
        [MapTo("coordinates")]
        private IList<double> Coordinates { get; } = null!;
    
        [MapTo("type")]
        private string Type { get; set; } = "Point";
    
        public double Latitude => Coordinates.Count > 1 ? Coordinates[1] : throw new Exception($"Invalid coordinate array. Expected at least 2 elements, but got: {Coordinates.Count}");
    
        public double Longitude => Coordinates.Count > 1 ? Coordinates[0] : throw new Exception($"Invalid coordinate array. Expected at least 2 elements, but got: {Coordinates.Count}");
    
        public MyGeoPoint(double latitude, double longitude)
        {
            Coordinates.Add(longitude);
            Coordinates.Add(latitude);
        }
    }
    | Edit this page View Source

    Like(string?, string, bool)

    Performs a 'like' comparison between the specified string and pattern.

    Declaration
    public static bool Like(string? str, string pattern, bool caseSensitive = true)
    Parameters
    Type Name Description
    string str

    The string to compare against the pattern.

    string pattern

    The pattern to compare against.

    bool caseSensitive

    If set to true performs a case sensitive comparison.

    Returns
    Type Description
    bool

    true if the string matches the pattern, false otherwise.

    Remarks

    ? and are allowed where ? matches a single character and matches zero or more characters, such that ?bc* matches abcde and bbc, but does not match bcd.

    This extension method can be used in LINQ queries against the IQueryable returned from All<T>(). If used outside of a query context, it will use a Regex to perform the comparison using the same rules.
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2020-2024 Realm
    Generated by DocFX