Search Results for

    Show / Hide Table of Contents

    Class LinqOptions

    Inheritance
    object
    LinqOptions
    Implements
    IOptionSet
    IConfigurationID
    IEquatable<LinqOptions>
    Namespace: LinqToDB
    Assembly: linq2db.dll
    Syntax
    public sealed record LinqOptions : IOptionSet, IConfigurationID, IEquatable<LinqOptions>

    Constructors

    | Improve this Doc View Source

    LinqOptions()

    Declaration
    public LinqOptions()
    | Improve this Doc View Source

    LinqOptions(bool, bool, bool, bool, bool, bool, bool, bool, bool, TimeSpan?, bool, bool, bool, bool)

    Declaration
    public LinqOptions(bool PreloadGroups = false, bool IgnoreEmptyUpdate = false, bool GenerateExpressionTest = false, bool TraceMapperExpression = false, bool DoNotClearOrderBys = false, bool OptimizeJoins = true, bool CompareNullsAsValues = true, bool GuardGrouping = true, bool DisableQueryCache = false, TimeSpan? CacheSlidingExpiration = null, bool PreferApply = true, bool KeepDistinctOrdered = true, bool ParameterizeTakeSkip = true, bool EnableContextSchemaEdit = false)
    Parameters
    Type Name Description
    bool PreloadGroups

    Controls how group data for LINQ queries ended with GroupBy will be loaded:

    • if true - group data will be loaded together with main query, resulting in 1 + N queries, where N - number of groups;
    • if false - group data will be loaded when you call enumerator for specific group IGrouping<TKey,TElement>. Default value: false.
    bool IgnoreEmptyUpdate

    Controls behavior of linq2db when there is no updateable fields in Update query:

    • if true - query not executed and Update operation returns 0 as number of affected records;
    • if false - LinqException will be thrown. Default value: false.
    bool GenerateExpressionTest

    Enables generation of test class for each LINQ query, executed while this option is enabled. This option could be useful for issue reporting, when you need to provide reproducible case. Test file will be placed to linq2db subfolder of temp folder and exact file path will be logged to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

    bool TraceMapperExpression

    Enables logging of generated mapping expression to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

    bool DoNotClearOrderBys

    Controls behavior, when LINQ query chain contains multiple OrderBy<TSource,TKey>(IQueryable<TSource>, Expression<Func<TSource,TKey>>) or OrderByDescending<TSource,TKey>(IQueryable<TSource>, Expression<Func<TSource,TKey>>) calls:

    • if true - non-first OrderBy* call will be treated as ThenBy* call;
    • if false - OrderBy* call will discard sort specifications, added by previous OrderBy* and ThenBy* calls. Default value: false.
    bool OptimizeJoins

    If enabled, linq2db will try to reduce number of generated SQL JOINs for LINQ query. Attempted optimizations:

    • removes duplicate joins by unique target table key;
    • removes self-joins by unique key;
    • removes left joins if joined table is not used in query. Default value: true.
    bool CompareNullsAsValues If set to true nullable fields would be checked for IS NULL in Equal/NotEqual comparisons. This affects: Equal, NotEqual, Not Contains Default value: true.
    public class MyEntity
    {
        public int? Value;
    }
    

    db.MyEntity.Where(e => e.Value != 10)

    from e1 in db.MyEntity join e2 in db.MyEntity on e1.Value equals e2.Value select e1

    var filter = new [] {1, 2, 3}; db.MyEntity.Where(e => ! filter.Contains(e.Value))

    Would be converted to next queries:

    SELECT Value FROM MyEntity WHERE Value IS NULL OR Value != 10
    
    SELECT e1.Value
    FROM MyEntity e1
    INNER JOIN MyEntity e2 ON e1.Value = e2.Value OR (e1.Value IS NULL AND e2.Value IS NULL)
    
    SELECT Value FROM MyEntity WHERE Value IS NULL OR NOT Value IN (1, 2, 3)
    bool GuardGrouping Controls behavior of LINQ query, which ends with GroupBy call. - if true - LinqToDBException will be thrown for such queries; - if false - behavior is controlled by PreloadGroups option. Default value: true. More details.
    bool DisableQueryCache Used to disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects:

    - cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code

    - cache access synchronization could lead to bigger latencies than it saves.

    Default value: false.

    It is not recommended to enable this option as it could lead to severe slowdown. Better approach will be to call ClearCache() method to cleanup cache after queries, that produce severe memory leaks you need to fix.

    More details.
    TimeSpan? CacheSlidingExpiration

    Specifies timeout when query will be evicted from cache since last execution of query. Default value is 1 hour.

    bool PreferApply

    Used to generate CROSS APPLY or OUTER APPLY if possible. Default value: true.

    bool KeepDistinctOrdered

    Allows SQL generation to automatically transform

    SELECT DISTINCT value FROM Table ORDER BY date

    Into GROUP BY equivalent if syntax is not supported Default value: true.

    bool ParameterizeTakeSkip

    Enables Take/Skip parameterization. Default value: true.

    bool EnableContextSchemaEdit

    If true, user could add new mappings to context mapping schems (MappingSchema). Otherwise LinqToDBException will be generated on locked mapping schema edit attempt. It is not recommended to enable this option as it has performance implications. Proper approach is to create single MappingSchema instance once, configure mappings for it and use this MappingSchema instance for all context instances. Default value: false.

    Properties

    | Improve this Doc View Source

    CacheSlidingExpiration

    Specifies timeout when query will be evicted from cache since last execution of query. Default value is 1 hour.

    Declaration
    public TimeSpan? CacheSlidingExpiration { get; init; }
    Property Value
    Type Description
    TimeSpan?
    | Improve this Doc View Source

    CacheSlidingExpirationOrDefault

    Declaration
    public TimeSpan CacheSlidingExpirationOrDefault { get; }
    Property Value
    Type Description
    TimeSpan
    | Improve this Doc View Source

    CompareNullsAsValues

    If set to true nullable fields would be checked for IS NULL in Equal/NotEqual comparisons. This affects: Equal, NotEqual, Not Contains Default value: true.
    public class MyEntity
    {
        public int? Value;
    }
    

    db.MyEntity.Where(e => e.Value != 10)

    from e1 in db.MyEntity join e2 in db.MyEntity on e1.Value equals e2.Value select e1

    var filter = new [] {1, 2, 3}; db.MyEntity.Where(e => ! filter.Contains(e.Value))

    Would be converted to next queries:

    SELECT Value FROM MyEntity WHERE Value IS NULL OR Value != 10
    
    SELECT e1.Value
    FROM MyEntity e1
    INNER JOIN MyEntity e2 ON e1.Value = e2.Value OR (e1.Value IS NULL AND e2.Value IS NULL)
    
    SELECT Value FROM MyEntity WHERE Value IS NULL OR NOT Value IN (1, 2, 3)
    Declaration
    public bool CompareNullsAsValues { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    DisableQueryCache

    Used to disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects:

    - cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code

    - cache access synchronization could lead to bigger latencies than it saves.

    Default value: false.

    It is not recommended to enable this option as it could lead to severe slowdown. Better approach will be to call ClearCache() method to cleanup cache after queries, that produce severe memory leaks you need to fix.

    More details.
    Declaration
    public bool DisableQueryCache { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    DoNotClearOrderBys

    Controls behavior, when LINQ query chain contains multiple OrderBy<TSource,TKey>(IQueryable<TSource>, Expression<Func<TSource,TKey>>) or OrderByDescending<TSource,TKey>(IQueryable<TSource>, Expression<Func<TSource,TKey>>) calls:

    • if true - non-first OrderBy* call will be treated as ThenBy* call;
    • if false - OrderBy* call will discard sort specifications, added by previous OrderBy* and ThenBy* calls. Default value: false.
    Declaration
    public bool DoNotClearOrderBys { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    EnableContextSchemaEdit

    If true, user could add new mappings to context mapping schems (MappingSchema). Otherwise LinqToDBException will be generated on locked mapping schema edit attempt. It is not recommended to enable this option as it has performance implications. Proper approach is to create single MappingSchema instance once, configure mappings for it and use this MappingSchema instance for all context instances. Default value: false.

    Declaration
    public bool EnableContextSchemaEdit { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    GenerateExpressionTest

    Enables generation of test class for each LINQ query, executed while this option is enabled. This option could be useful for issue reporting, when you need to provide reproducible case. Test file will be placed to linq2db subfolder of temp folder and exact file path will be logged to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

    Declaration
    public bool GenerateExpressionTest { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    GuardGrouping

    Controls behavior of LINQ query, which ends with GroupBy call. - if true - LinqToDBException will be thrown for such queries; - if false - behavior is controlled by PreloadGroups option. Default value: true. More details.
    Declaration
    public bool GuardGrouping { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    IgnoreEmptyUpdate

    Controls behavior of linq2db when there is no updateable fields in Update query:

    • if true - query not executed and Update operation returns 0 as number of affected records;
    • if false - LinqException will be thrown. Default value: false.
    Declaration
    public bool IgnoreEmptyUpdate { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    KeepDistinctOrdered

    Allows SQL generation to automatically transform

    SELECT DISTINCT value FROM Table ORDER BY date

    Into GROUP BY equivalent if syntax is not supported Default value: true.

    Declaration
    public bool KeepDistinctOrdered { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    OptimizeJoins

    If enabled, linq2db will try to reduce number of generated SQL JOINs for LINQ query. Attempted optimizations:

    • removes duplicate joins by unique target table key;
    • removes self-joins by unique key;
    • removes left joins if joined table is not used in query. Default value: true.
    Declaration
    public bool OptimizeJoins { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    ParameterizeTakeSkip

    Enables Take/Skip parameterization. Default value: true.

    Declaration
    public bool ParameterizeTakeSkip { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    PreferApply

    Used to generate CROSS APPLY or OUTER APPLY if possible. Default value: true.

    Declaration
    public bool PreferApply { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    PreloadGroups

    Controls how group data for LINQ queries ended with GroupBy will be loaded:

    • if true - group data will be loaded together with main query, resulting in 1 + N queries, where N - number of groups;
    • if false - group data will be loaded when you call enumerator for specific group IGrouping<TKey,TElement>. Default value: false.
    Declaration
    public bool PreloadGroups { get; init; }
    Property Value
    Type Description
    bool
    | Improve this Doc View Source

    TraceMapperExpression

    Enables logging of generated mapping expression to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

    Declaration
    public bool TraceMapperExpression { get; init; }
    Property Value
    Type Description
    bool

    Methods

    | Improve this Doc View Source

    Equals(LinqOptions?)

    Declaration
    public bool Equals(LinqOptions? other)
    Parameters
    Type Name Description
    LinqOptions other
    Returns
    Type Description
    bool
    | Improve this Doc View Source

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    Object.GetHashCode()

    Implements

    IOptionSet
    IConfigurationID
    System.IEquatable<T>

    Extension Methods

    DataOptionsExtensions.WithCacheSlidingExpiration(LinqOptions, TimeSpan?)
    DataOptionsExtensions.WithCompareNullsAsValues(LinqOptions, bool)
    DataOptionsExtensions.WithDisableQueryCache(LinqOptions, bool)
    DataOptionsExtensions.WithDoNotClearOrderBys(LinqOptions, bool)
    DataOptionsExtensions.WithEnableContextSchemaEdit(LinqOptions, bool)
    DataOptionsExtensions.WithGenerateExpressionTest(LinqOptions, bool)
    DataOptionsExtensions.WithGuardGrouping(LinqOptions, bool)
    DataOptionsExtensions.WithKeepDistinctOrdered(LinqOptions, bool)
    DataOptionsExtensions.WithOptimizeJoins(LinqOptions, bool)
    DataOptionsExtensions.WithParameterizeTakeSkip(LinqOptions, bool)
    DataOptionsExtensions.WithPreferApply(LinqOptions, bool)
    DataOptionsExtensions.WithPreloadGroups(LinqOptions, bool)
    DataOptionsExtensions.WithTraceMapperExpression(LinqOptions, bool)
    Sql.IsDistinctFrom<T>(T, T)
    Sql.IsNotDistinctFrom<T>(T, T)
    Map.DeepCopy<T>(T)
    SqlExtensions.In<T>(T, T, T, T)
    SqlExtensions.In<T>(T, T, T)
    SqlExtensions.In<T>(T, params T[])
    SqlExtensions.In<T>(T, IEnumerable<T>)
    SqlExtensions.In<T>(T, IQueryable<T>)
    SqlExtensions.NotIn<T>(T, T, T, T)
    SqlExtensions.NotIn<T>(T, T, T)
    SqlExtensions.NotIn<T>(T, params T[])
    SqlExtensions.NotIn<T>(T, IEnumerable<T>)
    SqlExtensions.NotIn<T>(T, IQueryable<T>)
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2011-2023 linq2db.com

    Generated by DocFX