diff --git a/Orm/Xtensive.Orm.Firebird/Orm.Providers.Firebird/SqlCompiler.cs b/Orm/Xtensive.Orm.Firebird/Orm.Providers.Firebird/SqlCompiler.cs index 26c8cebf19..0426acc607 100644 --- a/Orm/Xtensive.Orm.Firebird/Orm.Providers.Firebird/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.Firebird/Orm.Providers.Firebird/SqlCompiler.cs @@ -8,13 +8,6 @@ namespace Xtensive.Orm.Providers.Firebird { - internal class SqlCompiler : Providers.SqlCompiler - { - // Constructors - - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) - : base(handlers, configuration) - { - } - } -} \ No newline at end of file + internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) + : Providers.SqlCompiler(handlers, configuration); +} diff --git a/Orm/Xtensive.Orm.MySql/Orm.Providers.MySql/SqlCompiler.cs b/Orm/Xtensive.Orm.MySql/Orm.Providers.MySql/SqlCompiler.cs index e8cb5d4c9b..e8a3ec49fa 100644 --- a/Orm/Xtensive.Orm.MySql/Orm.Providers.MySql/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.MySql/Orm.Providers.MySql/SqlCompiler.cs @@ -9,13 +9,6 @@ namespace Xtensive.Orm.Providers.MySql { - internal class SqlCompiler : Providers.SqlCompiler - { - // Constructors - - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) - : base(handlers, configuration) - { - } - } -} \ No newline at end of file + internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) + : Providers.SqlCompiler(handlers, configuration); +} diff --git a/Orm/Xtensive.Orm.Oracle/Orm.Providers.Oracle/SqlCompiler.cs b/Orm/Xtensive.Orm.Oracle/Orm.Providers.Oracle/SqlCompiler.cs index 923c26dfb4..b5f149924d 100644 --- a/Orm/Xtensive.Orm.Oracle/Orm.Providers.Oracle/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.Oracle/Orm.Providers.Oracle/SqlCompiler.cs @@ -37,9 +37,9 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, IReadOnlyL // Constructors - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) + public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) : base(handlers, configuration) { } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs index 27945b097a..6e8bd7a14f 100644 --- a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs +++ b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs @@ -35,4 +35,4 @@ protected override IEnumerable GetProviderCompilerContainers() }); } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs index 1f7f9e0d2f..094eb81188 100644 --- a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs @@ -62,7 +62,7 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, IReadOnlyL return result; } - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) + public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) : base(handlers, configuration) { } diff --git a/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/DomainHandler.cs b/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/DomainHandler.cs index 30a34371e8..21407bad60 100644 --- a/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/DomainHandler.cs +++ b/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/DomainHandler.cs @@ -17,10 +17,7 @@ namespace Xtensive.Orm.Providers.SqlServer public class DomainHandler : Providers.DomainHandler { /// - protected override ICompiler CreateCompiler(CompilerConfiguration configuration) - { - return new SqlCompiler(Handlers, configuration); - } + protected override ICompiler CreateCompiler(CompilerConfiguration configuration) => new SqlCompiler(Handlers, configuration); /// protected override SearchConditionCompiler CreateSearchConditionVisitor() @@ -30,4 +27,4 @@ protected override SearchConditionCompiler CreateSearchConditionVisitor() return new SearchConditionCompilerV11(); } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/SqlCompiler.cs b/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/SqlCompiler.cs index d02e718903..f4111d5ca1 100644 --- a/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.SqlServer/Orm.Providers.SqlServer/SqlCompiler.cs @@ -15,7 +15,7 @@ namespace Xtensive.Orm.Providers.SqlServer { - internal class SqlCompiler : Providers.SqlCompiler + internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) : Providers.SqlCompiler(handlers, configuration) { private static readonly Type ByteType = typeof(byte); private static readonly Type Int16Type = typeof(short); @@ -149,12 +149,5 @@ private bool ShouldCastDueType(Type type) || type == DecimalType || type == FloatType; } - - // Constructors - - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) - : base(handlers, configuration) - { - } } } diff --git a/Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/ColumnResolver.cs b/Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/ColumnResolver.cs index 61f10b951e..39d1eed9bb 100644 --- a/Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/ColumnResolver.cs +++ b/Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/ColumnResolver.cs @@ -4,59 +4,35 @@ // Created by: Dmitri Maximov // Created: 2009.08.12 -using System; -using System.Collections.Generic; -using System.Linq; using Xtensive.Sql.Model; namespace Xtensive.Sql.Drivers.SqlServer.v09 { - internal sealed class ColumnResolver + internal sealed class ColumnResolver(DataTable table) { - public DataTable Table; - private List columnMappings; - - private class ColumnIndexMapping - { - public readonly int DbIndex; - public readonly int ModelIndex; - - public ColumnIndexMapping(int dbIndex, int modelIndex) - { - DbIndex = dbIndex; - ModelIndex = modelIndex; - } - } + private readonly record struct ColumnIndexMapping(int DbIndex, int ModelIndex, bool IsValid); - public void RegisterColumnMapping(int dbIndex, int modelIndex) - { - if (columnMappings == null) - columnMappings = new List(1); + public DataTable Table = table; + private List columnMappings; - columnMappings.Add(new ColumnIndexMapping(dbIndex, modelIndex)); - } + public void RegisterColumnMapping(int dbIndex, int modelIndex) => + (columnMappings ??= new(1)).Add(new ColumnIndexMapping(dbIndex, modelIndex, true)); public DataTableColumn GetColumn(int dbIndex) { int modelIndex = dbIndex-1; - var view = Table as View; - if (view != null) + if (Table is View view) return view.ViewColumns[modelIndex]; var table = (Table)Table; if (columnMappings == null) return table.TableColumns[modelIndex]; - var mapping = columnMappings.Where(item => item.DbIndex==dbIndex).FirstOrDefault(); - if (mapping != null) + var mapping = columnMappings.FirstOrDefault(item => item.DbIndex==dbIndex); + if (mapping != default) return table.TableColumns[mapping.ModelIndex]; throw new ArgumentOutOfRangeException("dbIndex"); } - - public ColumnResolver(DataTable table) - { - Table = table; - } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm.Sqlite/Orm.Providers.Sqlite/SqlCompiler.cs b/Orm/Xtensive.Orm.Sqlite/Orm.Providers.Sqlite/SqlCompiler.cs index 6d886b74fe..4c40025a10 100644 --- a/Orm/Xtensive.Orm.Sqlite/Orm.Providers.Sqlite/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.Sqlite/Orm.Providers.Sqlite/SqlCompiler.cs @@ -8,14 +8,6 @@ namespace Xtensive.Orm.Providers.Sqlite { - internal class SqlCompiler : Providers.SqlCompiler - { - - // Constructors - - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) - : base(handlers, configuration) - { - } - } -} \ No newline at end of file + internal class SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) + : Providers.SqlCompiler(handlers, configuration); +} diff --git a/Orm/Xtensive.Orm/Core/AliasGenerator.cs b/Orm/Xtensive.Orm/Core/AliasGenerator.cs index 8550343d47..072b6963a3 100644 --- a/Orm/Xtensive.Orm/Core/AliasGenerator.cs +++ b/Orm/Xtensive.Orm/Core/AliasGenerator.cs @@ -12,7 +12,7 @@ namespace Xtensive.Core /// Universal alias generator. /// [Serializable] - public sealed class AliasGenerator + public struct AliasGenerator { /// /// Default alias template. Value is "{0}{1}". Where {0} - template parameter for prefix and {1} - template parameter for suffix. @@ -93,7 +93,7 @@ public static AliasGenerator Create(string[] overriddenPrefixes, string aliasTem // Constructors - private AliasGenerator() + public AliasGenerator() : this (DefaultAliasTemplate) {} @@ -111,4 +111,4 @@ private AliasGenerator(string[] prefixes, string aliasTemplate) this.aliasTemplate = aliasTemplate; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs b/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs index ceea7fef93..b66a9bdf2a 100644 --- a/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs @@ -485,18 +485,18 @@ private KeyInfo BuildKeyInfo(TypeInfo root, HierarchyDef hierarchyDef) var keyFields = root.Fields .Where(static field => field.IsPrimaryKey) .OrderBy(static field => field.MappingInfo.Offset) - .ToList(); + .ToArray(); var keyColumns = keyFields .Where(static field => field.Column != null) .Select(static field => field.Column) - .ToList(); + .ToArray(); var keyTupleDescriptor = TupleDescriptor.Create( - keyColumns.Select(static c => c.ValueType).ToArray(keyColumns.Count)); + keyColumns.Select(static c => c.ValueType).ToArray(keyColumns.Length)); var typeIdColumnIndex = -1; if (hierarchyDef.IncludeTypeId) { - for (var i = 0; i < keyColumns.Count; i++) { + for (var i = 0; i < keyColumns.Length; i++) { if (keyColumns[i].Field.IsTypeId) { typeIdColumnIndex = i; } @@ -640,4 +640,4 @@ public TypeBuilder(BuildingContext context) .ToDictionary(configuration => context.NameBuilder.BuildKeyGeneratorName(configuration)); } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/QueryProvider.cs b/Orm/Xtensive.Orm/Orm/Linq/QueryProvider.cs index 91575d0e2c..d14d325b5d 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/QueryProvider.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/QueryProvider.cs @@ -168,7 +168,7 @@ internal TranslatedQuery Translate(Expression expression) => Translate(expression, Session.CompilationService.CreateConfiguration(Session)); internal TranslatedQuery Translate(Expression expression, - CompilerConfiguration compilerConfiguration) + in CompilerConfiguration compilerConfiguration) { try { var compiledQueryScope = CompiledQueryProcessingScope.Current; @@ -189,4 +189,4 @@ internal QueryProvider(Session session) Session = session; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Rewriters/AggregateOptimizer.cs b/Orm/Xtensive.Orm/Orm/Linq/Rewriters/AggregateOptimizer.cs index 7b97e45968..ed2944ade2 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Rewriters/AggregateOptimizer.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Rewriters/AggregateOptimizer.cs @@ -21,6 +21,8 @@ namespace Xtensive.Orm.Linq.Rewriters { internal sealed class AggregateOptimizer : ExtendedExpressionVisitor { + private static readonly AggregateOptimizer Instance = new(); + private sealed class GroupByItemWrapper { public TKey Key { get; set; } @@ -214,7 +216,7 @@ public static Expression Rewrite(Expression expression) // This would help Translator to translate GroupBy+Aggregate // into single AggregateProvider. - return new AggregateOptimizer().Visit(expression); + return Instance.Visit(expression); } private static void AddGroupByItemWrapper(GroupByQuery groupBy, List elementProjections) @@ -284,4 +286,4 @@ private AggregateOptimizer() { } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs b/Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs index 4695692b72..9ba72f4208 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs @@ -25,14 +25,14 @@ namespace Xtensive.Orm.Linq { internal sealed class TranslatorContext { - private readonly AliasGenerator resultAliasGenerator; - private readonly AliasGenerator columnAliasGenerator; + private AliasGenerator resultAliasGenerator = AliasGenerator.Create("#{0}{1}"); + private AliasGenerator columnAliasGenerator = AliasGenerator.Create(new[] {"c01umn"}); private readonly Dictionary> tupleParameters; private readonly Dictionary applyParameters; private readonly Dictionary boundItemProjectors; private readonly Dictionary queryReuses; - public CompilerConfiguration RseCompilerConfiguration { get; } + public readonly CompilerConfiguration RseCompilerConfiguration; public ProviderInfo ProviderInfo { get; } @@ -124,11 +124,7 @@ public ItemProjectorExpression GetBoundItemProjector(ParameterExpression paramet return result; } - public void RegisterPossibleQueryReuse(MemberInfo memberInfo) - { - if (!queryReuses.ContainsKey(memberInfo)) - queryReuses.Add(memberInfo, 0); - } + public void RegisterPossibleQueryReuse(MemberInfo memberInfo) => queryReuses.TryAdd(memberInfo, 0); public bool CheckIfQueryReusePossible(MemberInfo memberInfo) { @@ -148,11 +144,10 @@ private Expression ApplyPreprocessor(IQueryPreprocessor preprocessor, Session se // Constructors - public TranslatorContext(Session session, CompilerConfiguration rseCompilerConfiguration, Expression query, + public TranslatorContext(Session session, in CompilerConfiguration rseCompilerConfiguration, Expression query, CompiledQueryProcessingScope compiledQueryScope) { ArgumentNullException.ThrowIfNull(session); - ArgumentNullException.ThrowIfNull(rseCompilerConfiguration); ArgumentNullException.ThrowIfNull(query); Domain = session.Domain; @@ -173,8 +168,6 @@ public TranslatorContext(Session session, CompilerConfiguration rseCompilerConfi query = PersistentIndexerRewriter.Rewrite(query, this); Query = query; - resultAliasGenerator = AliasGenerator.Create("#{0}{1}"); - columnAliasGenerator = AliasGenerator.Create(new[] {"c01umn"}); CustomCompilerProvider = Domain.Handler.GetMemberCompilerProvider(); Model = Domain.Model; TypeIdRegistry = session.StorageNode.TypeIdRegistry; diff --git a/Orm/Xtensive.Orm/Orm/Providers/CompilationService.cs b/Orm/Xtensive.Orm/Orm/Providers/CompilationService.cs index ac41c134e3..906bb52e73 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/CompilationService.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/CompilationService.cs @@ -14,19 +14,20 @@ namespace Xtensive.Orm.Providers /// /// compilation service. /// - public sealed class CompilationService + public readonly struct CompilationService { private readonly Func compilerProvider; private readonly Func preCompilerProvider; private readonly Func postCompilerProvider; public CompilerConfiguration CreateConfiguration(Session session) => - new() { - StorageNode = session.StorageNode, - Tags = session.Tags, + new( + PrepareRequest: true, + StorageNode: session.StorageNode, + Tags: session.Tags, // prefer constants during upgrade process - PreferTypeIdAsParameter = !session.Name.Equals(WellKnown.Sessions.System) && session.Domain.Configuration.PreferTypeIdsAsQueryParameters - }; + PreferTypeIdAsParameter: !session.Name.Equals(WellKnown.Sessions.System) && session.Domain.Configuration.PreferTypeIdsAsQueryParameters + ); public ExecutableProvider Compile(CompilableProvider provider, CompilerConfiguration configuration) { @@ -58,12 +59,12 @@ public CompilationService( Func postCompilerProvider) { ArgumentNullException.ThrowIfNull(compilerProvider); - ArgumentNullException.ThrowIfNull(compilerProvider, "preCompilerProvider"); - ArgumentNullException.ThrowIfNull(compilerProvider, "postCompilerProvider"); + ArgumentNullException.ThrowIfNull(preCompilerProvider); + ArgumentNullException.ThrowIfNull(postCompilerProvider); this.compilerProvider = compilerProvider; this.preCompilerProvider = preCompilerProvider; this.postCompilerProvider = postCompilerProvider; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Providers/CompilerConfiguration.cs b/Orm/Xtensive.Orm/Orm/Providers/CompilerConfiguration.cs index 46c2649f3a..2686ab7966 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/CompilerConfiguration.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/CompilerConfiguration.cs @@ -8,20 +8,11 @@ namespace Xtensive.Orm.Providers { - public sealed class CompilerConfiguration - { - public bool PrepareRequest { get; set; } - public bool PreferTypeIdAsParameter { get; set; } - public IReadOnlyList Tags { get; init; } - - internal StorageNode StorageNode { get; set; } - - - // Constructors - - public CompilerConfiguration() - { - PrepareRequest = true; - } - } -} \ No newline at end of file + public readonly record struct CompilerConfiguration + ( + bool PrepareRequest, + bool PreferTypeIdAsParameter, + IReadOnlyList Tags, + StorageNode StorageNode + ); +} diff --git a/Orm/Xtensive.Orm/Orm/Providers/DomainHandler.cs b/Orm/Xtensive.Orm/Orm/Providers/DomainHandler.cs index 6e7824d522..2f716f056f 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/DomainHandler.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/DomainHandler.cs @@ -109,13 +109,10 @@ protected virtual IPreCompiler CreatePreCompiler(CompilerConfiguration configura /// Compiler configuration to use. /// Currently used compiler instance. /// A new post-compiler. - protected virtual IPostCompiler CreatePostCompiler(CompilerConfiguration configuration, ICompiler compiler) - { - var result = new CompositePostCompiler(new SqlSelectCorrector(Handlers.ProviderInfo)); - if (configuration.PrepareRequest) - result.Items.Add(new SqlProviderPreparer(Handlers)); - return result; - } + protected virtual IPostCompiler CreatePostCompiler(CompilerConfiguration configuration, ICompiler compiler) => + configuration.PrepareRequest + ? new CompositePostCompiler([new SqlSelectCorrector(Handlers.ProviderInfo), new SqlProviderPreparer(Handlers)]) + : new CompositePostCompiler([new SqlSelectCorrector(Handlers.ProviderInfo)]); /// /// Gets compiler containers specific to current storage provider. @@ -214,4 +211,4 @@ public void InitializeServices() BuildQueryPreprocessors(); } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs index 17c02d4b41..3969f90df8 100644 --- a/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs +++ b/Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs @@ -594,7 +594,7 @@ protected override void Initialize() /// /// Initializes a new instance of this class. /// - public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration) + public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration) { Handlers = handlers; OuterReferences = new BindingCollection>(); diff --git a/Orm/Xtensive.Orm/Orm/Rse/Compilation/CompositePostCompiler.cs b/Orm/Xtensive.Orm/Orm/Rse/Compilation/CompositePostCompiler.cs index 0c781c76bc..eeb941ceaa 100644 --- a/Orm/Xtensive.Orm/Orm/Rse/Compilation/CompositePostCompiler.cs +++ b/Orm/Xtensive.Orm/Orm/Rse/Compilation/CompositePostCompiler.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Xtensive LLC. +// Copyright (C) 2012 Xtensive LLC. // All rights reserved. // For conditions of distribution and use, see license. // Created by: Denis Krjuchkov @@ -10,9 +10,9 @@ namespace Xtensive.Orm.Rse.Compilation { - public class CompositePostCompiler : IPostCompiler + public class CompositePostCompiler(IReadOnlyList items) : IPostCompiler { - public List Items { get; private set; } + public IReadOnlyList Items { get; } = items; public ExecutableProvider Process(ExecutableProvider rootProvider) { @@ -21,13 +21,5 @@ public ExecutableProvider Process(ExecutableProvider rootProvider) provider = item.Process(provider); return provider; } - - - // Constructors - - public CompositePostCompiler(params IPostCompiler[] postCompilers) - { - Items = postCompilers.ToList(); - } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryBuilder.cs b/Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryBuilder.cs index 9de43a936d..44d342468e 100644 --- a/Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryBuilder.cs +++ b/Orm/Xtensive.Orm/Orm/Services/QueryBuilding/QueryBuilder.cs @@ -37,8 +37,7 @@ public QueryTranslationResult TranslateQuery(IQueryable query) { ArgumentNullException.ThrowIfNull(query); - var configuration = Session.CompilationService.CreateConfiguration(Session); - configuration.PrepareRequest = false; + var configuration = Session.CompilationService.CreateConfiguration(Session) with { PrepareRequest = false }; var translated = queryProvider.Translate(query.Expression, configuration); var sqlProvider = translated.DataSource as SqlProvider; @@ -124,4 +123,4 @@ public QueryBuilder(Session session) queryProvider = session.Query.Provider; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Services/QueryFormatter.cs b/Orm/Xtensive.Orm/Orm/Services/QueryFormatter.cs index b1ab291957..dbe1c75a78 100644 --- a/Orm/Xtensive.Orm/Orm/Services/QueryFormatter.cs +++ b/Orm/Xtensive.Orm/Orm/Services/QueryFormatter.cs @@ -69,8 +69,7 @@ public DbCommand ToDbCommand(IQueryable query) private CommandPart GetCommandPart(IQueryable query) { - var compilerConfiguration = Session.CompilationService.CreateConfiguration(Session); - compilerConfiguration.PreferTypeIdAsParameter = false; + var compilerConfiguration = Session.CompilationService.CreateConfiguration(Session) with { PreferTypeIdAsParameter = false }; var translatedQuery = Session.Query.Provider.Translate(query.Expression, compilerConfiguration); var sqlProvider = translatedQuery.DataSource as SqlProvider; @@ -93,4 +92,4 @@ public QueryFormatter(Session session) commandFactory = sqlSessionHandler.CommandFactory; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Session.cs b/Orm/Xtensive.Orm/Orm/Session.cs index 2f74feecb2..ba6e710487 100644 --- a/Orm/Xtensive.Orm/Orm/Session.cs +++ b/Orm/Xtensive.Orm/Orm/Session.cs @@ -242,7 +242,7 @@ public static Func Resolver internal RemovalProcessor RemovalProcessor { get; private set; } - internal CompilationService CompilationService { get { return Handlers.DomainHandler.CompilationService; } } + internal CompilationService CompilationService => Handlers.DomainHandler.CompilationService; internal IReadOnlyList Tags => tags; @@ -344,10 +344,8 @@ internal StorageNode GetStorageNodeInternal() return storageNode; } - internal ExecutableProvider Compile(CompilableProvider provider) - { - return CompilationService.Compile(provider, CompilationService.CreateConfiguration(this)); - } + internal ExecutableProvider Compile(CompilableProvider provider) => + CompilationService.Compile(provider, CompilationService.CreateConfiguration(this)); internal ExecutableProvider Compile(CompilableProvider provider, CompilerConfiguration configuration) { diff --git a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs index bd594c18f2..65d7333a34 100644 --- a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs +++ b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs @@ -34,8 +34,9 @@ public class NodeCollection: CollectionBaseSlim public override void Add(TNode item) { base.Add(item); - if (!string.IsNullOrEmpty(item.GetNameInternal())) - nameIndex.Add(item.GetNameInternal(), item); + var name = item.GetNameInternal(); + if (!string.IsNullOrEmpty(name)) + nameIndex.Add(name, item); } /// @@ -67,14 +68,9 @@ public override void Clear() /// /// Gets the at the specified index. /// - public TNode this[string index] { - get { - if (string.IsNullOrEmpty(index)) - return default(TNode); - TNode result; - return nameIndex.TryGetValue(index, out result) ? result : default(TNode); - } - } + public TNode this[string index] => string.IsNullOrEmpty(index) + ? default + : nameIndex.TryGetValue(index, out var result) ? result : default(TNode); // Constructors @@ -108,4 +104,4 @@ public NodeCollection(int capacity, IEqualityComparer comparer) nameIndex = new Dictionary(capacity, comparer); } } -} \ No newline at end of file +}