Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EngineEdition more readable #31038

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ private static readonly ISet<string> MaxLengthRequiredTypes
"nvarchar"
};

private enum EngineEdition
{
SqlDataWarehouse = 6,
SqlOnDemand = 11,
DynamicsTdsEndpoint = 1000,
}

private const string NamePartRegex
= @"(?:(?:\[(?<part{0}>(?:(?:\]\])|[^\]])+)\])|(?<part{0}>[^\.\[\]]+))";

Expand All @@ -67,7 +74,7 @@ private static readonly Regex PartExtractor
};

private byte? _compatibilityLevel;
private int? _engineEdition;
private EngineEdition? _engineEdition;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -172,11 +179,12 @@ public override DatabaseModel Create(DbConnection connection, DatabaseModelFacto
}
}

static int GetEngineEdition(DbConnection connection)
static EngineEdition GetEngineEdition(DbConnection connection)
{
using var command = connection.CreateCommand();
command.CommandText = "SELECT SERVERPROPERTY('EngineEdition');";
return (int)command.ExecuteScalar()!;
var result = command.ExecuteScalar();
return result != null ? (EngineEdition)Convert.ToInt32(result) : 0;
}

static byte GetCompatibilityLevel(DbConnection connection)
Expand Down Expand Up @@ -1362,22 +1370,25 @@ FROM [sys].[triggers] AS [tr]
}

private bool SupportsTemporalTable()
=> _compatibilityLevel >= 130 && (_engineEdition is not 6 and not 11 and not 1000);
=> _compatibilityLevel >= 130 && IsFullFeaturedEngineEdition();

private bool SupportsMemoryOptimizedTable()
=> _compatibilityLevel >= 120 && (_engineEdition is not 6 and not 11 and not 1000);
=> _compatibilityLevel >= 120 && IsFullFeaturedEngineEdition();

private bool SupportsSequences()
=> _compatibilityLevel >= 110 && (_engineEdition is not 6 and not 11 and not 1000);
=> _compatibilityLevel >= 110 && IsFullFeaturedEngineEdition();

private bool SupportsIndexes()
=> _engineEdition != 1000;
=> _engineEdition != EngineEdition.DynamicsTdsEndpoint;

private bool SupportsViews()
=> _engineEdition != 1000;
=> _engineEdition != EngineEdition.DynamicsTdsEndpoint;

private bool SupportsTriggers()
=> _engineEdition is not 6 and not 11 and not 1000;
=> IsFullFeaturedEngineEdition();

private bool IsFullFeaturedEngineEdition()
=> _engineEdition is not EngineEdition.SqlDataWarehouse and not EngineEdition.SqlOnDemand and not EngineEdition.DynamicsTdsEndpoint;

private static string DisplayName(string? schema, string name)
=> (!string.IsNullOrEmpty(schema) ? schema + "." : "") + name;
Expand Down