Class Configuration.Linq
LINQ query settings.
public static class Configuration.Linq
- Inheritance
-
objectConfiguration.Linq
Properties
CacheSlidingExpiration
Specifies timeout when query will be evicted from cache since last execution of query. Default value is 1 hour.
public static TimeSpan CacheSlidingExpiration { get; set; }
Property Value
CompareNulls
If set to LikeClr nullable fields would be checked for IS NULL in Equal/NotEqual comparisons.
If set to LikeSql comparisons are compiled straight to equivalent SQL operators,
which consider nulls values as not equal.
LikeSqlExceptParameters is a backward compatible option that works mostly as LikeSql,
but sniffs parameters value and changes = into IS NULL when parameters are null.
Comparisons to literal null are always compiled into IS NULL.
This affects: Equal, NotEqual, Not Contains
Default value: LikeClr.
public static CompareNulls CompareNulls { get; set; }
Property Value
Examples
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 under LikeClr:
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)
ConcatenateOrderBy
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 place sort specifications, added by previous OrderBy* and ThenBy* calls, after current call.
false.
Example:
query.OrderBy(r => r.FirstName).OrderBy(r => r.LastName)
// =true - non-first OrderBy* calls treated as ordering continuation (non-standard)
ORDER BY p.FIRST_NAME, p.LAST_NAME
// =false - last OrderBy* calls have higher priority like they should per API documentation
ORDER BY p.LAST_NAME, p.FIRST_NAME
// to completely discard old sort specification, use API:
query.OrderBy(r => r.FirstName).RemoveOrderBy().OrderBy(r => r.LastName)
// for any value will produce
ORDER BY p.LAST_NAME
public static bool ConcatenateOrderBy { get; set; }
Property Value
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 use NoLinqCache scope around queries, that produce severe memory leaks you need to fix.
More details.
public static bool DisableQueryCache { get; set; }
Property Value
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.
public static bool EnableContextSchemaEdit { get; set; }
Property Value
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.
public static bool GenerateExpressionTest { get; set; }
Property Value
GuardGrouping
Controls behavior of LINQ query, which ends with GroupBy call.
- if
true- LinqToDBException will be thrown for such queries; - if
false- eager loading used. Default value:true.
public static bool GuardGrouping { get; set; }
Property Value
Remarks
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- LinqToDBException will be thrown. Default value:false.
public static bool IgnoreEmptyUpdate { get; set; }
Property Value
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.
public static bool OptimizeJoins { get; set; }
Property Value
Options
Default LinqOptions options. Automatically synchronized with other settings in Configuration.Linq class.
public static LinqOptions Options { get; set; }
Property Value
ParameterizeTakeSkip
Enables Take/Skip parameterization.
Default value: true.
public static bool ParameterizeTakeSkip { get; set; }
Property Value
TraceMapperExpression
Enables logging of generated mapping expression to data connection tracing infrastructure.
See TraceSwitch for more details.
Default value: false.
public static bool TraceMapperExpression { get; set; }