Skip to content

Commit 6315454

Browse files
committed
DomainConfiguration.PreferTypeIdsAsQueryParameters
1 parent 54cf317 commit 6315454

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

Orm/Xtensive.Orm/Orm/Configuration/DomainConfiguration.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public class DomainConfiguration : ConfigurationBase
8181
/// </summary>
8282
public const bool DefaultEnsureConnectionIsAlive = true;
8383

84+
/// <summary>
85+
/// Default <see cref="PreferTypeIdsAsQueryParameters"/> value: <see langword="true" />.
86+
/// </summary>
87+
public const bool DefaultPreferTypeIdsAsQueryParameters = true;
88+
8489
#endregion
8590

8691
private static bool sectionNameIsDefined;
@@ -109,6 +114,7 @@ public class DomainConfiguration : ConfigurationBase
109114
private bool multidatabaseKeys = DefaultMultidatabaseKeys;
110115
private bool shareStorageSchemaOverNodes = DefaultShareStorageSchemaOverNodes;
111116
private bool ensureConnectionIsAlive = DefaultEnsureConnectionIsAlive;
117+
private bool preferTypeIdsAsQueryParameters = DefaultPreferTypeIdsAsQueryParameters;
112118
private DomainOptions options = DomainOptions.Default;
113119
private SchemaSyncExceptionFormat schemaSyncExceptionFormat = SchemaSyncExceptionFormat.Default;
114120
private MappingRuleCollection mappingRules = new MappingRuleCollection();
@@ -594,6 +600,18 @@ public bool EnsureConnectionIsAlive
594600
}
595601
}
596602

603+
/// <summary>
604+
/// Makes queries use parameters instead of constant values for persistent type identifiers.
605+
/// </summary>
606+
public bool PreferTypeIdsAsQueryParameters
607+
{
608+
get { return preferTypeIdsAsQueryParameters; }
609+
set {
610+
EnsureNotLocked();
611+
preferTypeIdsAsQueryParameters = value;
612+
}
613+
}
614+
597615
/// <summary>
598616
/// Defines where tags will be placed when used within queries.
599617
/// </summary>

Orm/Xtensive.Orm/Orm/Configuration/Elements/DomainConfigurationElement.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class DomainConfigurationElement : ConfigurationCollectionElementBase
5050
private const string FullTextChangeTrackingModeElementName = "fullTextChangeTrackingMode";
5151
private const string VersioningConventionElementName = "versioningConvention";
5252
private const string EnsureConnectionIsAliveElementName = "ensureConnectionIsAlive";
53+
private const string PreferTypeIdsAsQueryParametersElementName = "preferTypeIdsAsQueryParameters";
5354
private const string TagsLocationElementName = "tagsLocation";
5455

5556

@@ -403,6 +404,16 @@ public string TagsLocation
403404
set => this[TagsLocationElementName] = value;
404405
}
405406

407+
/// <summary>
408+
/// <see cref="DomainConfiguration.PreferTypeIdsAsQueryParameters" copy="true"/>
409+
/// </summary>
410+
[ConfigurationProperty(PreferTypeIdsAsQueryParametersElementName, DefaultValue = true)]
411+
public bool PreferTypeIdsAsQueryParameters
412+
{
413+
get { return (bool) this[PreferTypeIdsAsQueryParametersElementName]; }
414+
set { this[PreferTypeIdsAsQueryParametersElementName] = value; }
415+
}
416+
406417
/// <summary>
407418
/// Converts the element to a native configuration object it corresponds to -
408419
/// i.e. to a <see cref="DomainConfiguration"/> object.
@@ -434,6 +445,7 @@ public DomainConfiguration ToNative()
434445
MultidatabaseKeys = MultidatabaseKeys,
435446
ShareStorageSchemaOverNodes = ShareStorageSchemaOverNodes,
436447
EnsureConnectionIsAlive = EnsureConnectionIsAlive,
448+
PreferTypeIdsAsQueryParameters = PreferTypeIdsAsQueryParameters,
437449
FullTextChangeTrackingMode = ParseEnum<FullTextChangeTrackingMode>(FullTextChangeTrackingMode),
438450
VersioningConvention = VersioningConvention.ToNative(),
439451
TagsLocation = (TagsLocation) Enum.Parse(typeof(TagsLocation), TagsLocation, true),

Orm/Xtensive.Orm/Orm/Providers/CompilationService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public sealed class CompilationService
2121
private readonly Func<CompilerConfiguration, ICompiler, IPostCompiler> postCompilerProvider;
2222

2323
public CompilerConfiguration CreateConfiguration(Session session) =>
24-
new CompilerConfiguration { StorageNode = session.StorageNode, Tags = session.Tags };
24+
new() {
25+
StorageNode = session.StorageNode,
26+
Tags = session.Tags,
27+
PreferTypeIdAsParameter = session.Domain.Configuration.PreferTypeIdsAsQueryParameters
28+
};
2529

2630
public ExecutableProvider Compile(CompilableProvider provider, CompilerConfiguration configuration)
2731
{

Orm/Xtensive.Orm/Orm/Providers/CompilerConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Xtensive.Orm.Providers
1111
public sealed class CompilerConfiguration
1212
{
1313
public bool PrepareRequest { get; set; }
14+
public bool PreferTypeIdAsParameter { get; set; }
1415
public IReadOnlyList<string> Tags { get; init; }
1516

1617
internal StorageNode StorageNode { get; set; }

Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration
580580
providerInfo = Handlers.ProviderInfo;
581581
temporaryTablesSupported = DomainHandler.TemporaryTableManager.Supported;
582582
forceApplyViaReference = Handlers.StorageDriver.ServerInfo.Query.Features.HasFlag(Sql.Info.QueryFeatures.CrossApplyForSubqueriesOnly);
583-
useParameterForTypeId = Driver.ServerInfo.Query.Features.HasFlag(Sql.Info.QueryFeatures.ParameterAsColumn);
583+
useParameterForTypeId = configuration.PreferTypeIdAsParameter && Driver.ServerInfo.Query.Features.HasFlag(Sql.Info.QueryFeatures.ParameterAsColumn);
584584

585585
if (!providerInfo.Supports(ProviderFeatures.FullFeaturedBooleanExpressions)) {
586586
booleanExpressionConverter = new BooleanExpressionConverter(Driver);

0 commit comments

Comments
 (0)