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

API review changes #33412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/EFCore.Design/Extensions/ScaffoldingModelExtensions.cs
Expand Up @@ -809,17 +809,21 @@ valueGenerated switch
root = root?.Chain(isCyclic) ?? isCyclic;
}

if (sequence.IsCached != Sequence.DefaultIsCached)
var cacheSize = sequence.CacheSize;
if (cacheSize.HasValue)
{
var useNoCache = new FluentApiCodeFragment(nameof(SequenceBuilder.UseNoCache));
if (cacheSize != 1 && cacheSize != 0)
{
var useCache = new FluentApiCodeFragment(nameof(SequenceBuilder.UseCache)) { Arguments = { cacheSize } };

root = root?.Chain(useNoCache) ?? useNoCache;
}
else
{
var useCache = new FluentApiCodeFragment(nameof(SequenceBuilder.UseCache)) { Arguments = { sequence.CacheSize } };
root = root?.Chain(useCache) ?? useCache;
}
else
{
var useNoCache = new FluentApiCodeFragment(nameof(SequenceBuilder.UseNoCache));

root = root?.Chain(useCache) ?? useCache;
root = root?.Chain(useNoCache) ?? useNoCache;
}
}

return root;
Expand Down
Expand Up @@ -778,23 +778,13 @@ protected virtual void Generate(AlterSequenceOperation operation, IndentedString
.Append("cyclic: true");
}

if (operation.IsCached && operation.CacheSize.HasValue)
if (operation.CacheSize != null)
{
builder
.AppendLine(",")
.Append("cached: ")
.Append(Code.Literal(operation.IsCached))
.AppendLine(",")
.Append("cacheSize: ")
.Append(Code.Literal(operation.CacheSize));
}
else if (!operation.IsCached)
{
builder
.AppendLine(",")
.Append("cached: ")
.Append(Code.Literal(operation.IsCached));
}

if (operation.OldSequence.IncrementBy != 1)
{
Expand Down Expand Up @@ -827,23 +817,13 @@ protected virtual void Generate(AlterSequenceOperation operation, IndentedString
.Append("oldCyclic: true");
}

if (operation.OldSequence.IsCached && operation.OldSequence.CacheSize.HasValue)
if (operation.OldSequence.CacheSize.HasValue)
{
builder
.AppendLine(",")
.Append("oldCached: ")
.Append(Code.Literal(operation.OldSequence.IsCached))
.AppendLine(",")
.Append("oldCacheSize: ")
.Append(Code.Literal(operation.OldSequence.CacheSize));
}
else if (!operation.IsCached)
{
builder
.AppendLine(",")
.Append("oldCached: ")
.Append(Code.Literal(operation.OldSequence.IsCached));
}

builder.Append(")");

Expand Down Expand Up @@ -1061,23 +1041,13 @@ protected virtual void Generate(CreateSequenceOperation operation, IndentedStrin
.Append("cyclic: true");
}

if (operation.IsCached && operation.CacheSize.HasValue)
if (operation.CacheSize.HasValue)
{
builder
.AppendLine(",")
.Append("cached: ")
.Append(Code.Literal(operation.IsCached))
.AppendLine(",")
.Append("cacheSize: ")
.Append(Code.Literal(operation.CacheSize));
}
else if(!operation.IsCached)
{
builder
.AppendLine(",")
.Append("cached: ")
.Append(Code.Literal(operation.IsCached));
}

builder.Append(")");

Expand Down
Expand Up @@ -393,13 +393,7 @@ public virtual void Generate(string modelBuilderName, IModel model, IndentedStri
.Append(".IsCyclic()");
}

if (sequence.IsCached != Sequence.DefaultIsCached)
{
stringBuilder
.AppendLine()
.Append(".UseNoCache()");
}
else if (sequence.CacheSize != Sequence.DefaultCacheSize)
if (sequence.CacheSize.HasValue)
{
stringBuilder
.AppendLine()
Expand Down
Expand Up @@ -269,18 +269,10 @@ protected virtual ModelBuilder VisitDatabaseModel(ModelBuilder modelBuilder, Dat
builder.IsCyclic(sequence.IsCyclic.Value);
}

if (sequence.IsCached.HasValue && !sequence.IsCached.Value)
{
builder.UseNoCache();
}
else if (sequence.IsCached.HasValue && sequence.CacheSize.HasValue)
if (sequence.CacheSize.HasValue)
{
builder.UseCache(sequence.CacheSize);
}
else
{
builder.UseCache();
}

return builder;
}
Expand Down
Expand Up @@ -1688,23 +1688,13 @@ private void Create(ISequence sequence, string sequencesVariable, CSharpRuntimeA
.Append("maxValue: ").Append(code.Literal(sequence.MaxValue));
}

if (sequence.IsCached && sequence.CacheSize.HasValue)
if (sequence.CacheSize.HasValue)
{
mainBuilder
.AppendLine(",")
.Append("cached: ")
.Append(code.Literal(sequence.IsCached))
.AppendLine(",")
.Append("cacheSize: ")
.Append(code.Literal(sequence.CacheSize));
}
else if (!sequence.IsCached)
{
mainBuilder
.AppendLine(",")
.Append("cached: ")
.Append(code.Literal(sequence.IsCached));
}

if (sequence.ModelSchema is null && sequence.Schema is not null)
{
Expand Down
Expand Up @@ -331,7 +331,6 @@ private static RuntimeSequence Create(ISequence sequence, RuntimeModel runtimeMo
sequence.IsCyclic,
sequence.MinValue,
sequence.MaxValue,
sequence.IsCached,
sequence.CacheSize,
sequence.ModelSchema is null);

Expand Down
16 changes: 0 additions & 16 deletions src/EFCore.Relational/Metadata/IConventionSequence.cs
Expand Up @@ -116,22 +116,6 @@ public interface IConventionSequence : IReadOnlySequence, IConventionAnnotatable
/// <returns>The configuration source for <see cref="IReadOnlySequence.IsCyclic" />.</returns>
ConfigurationSource? GetIsCyclicConfigurationSource();

/// <summary>
/// Sets whether the sequence use preallocated values.
/// </summary>
/// <param name="cached">
/// If <see langword="true" />, then the sequence use preallocated values.
/// </param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
bool? SetIsCached(bool? cached, bool fromDataAnnotation = false);

/// <summary>
/// Gets the configuration source for <see cref="IReadOnlySequence.IsCached" />.
/// </summary>
/// <returns>The configuration source for <see cref="IReadOnlySequence.IsCached" />.</returns>
ConfigurationSource? GetIsCachedConfigurationSource();

/// <summary>
/// Sets the amount of preallocated values.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions src/EFCore.Relational/Metadata/IMutableSequence.cs
Expand Up @@ -47,11 +47,6 @@ public interface IMutableSequence : IReadOnlySequence, IMutableAnnotatable
/// </summary>
new bool IsCyclic { get; set; }

/// <summary>
/// Gets or sets the value indicating whether the sequence use preallocated values.
/// </summary>
new bool IsCached { get; set; }

/// <summary>
/// Gets or sets the amount of preallocated values, or <see langword="null" /> if none has been set.
/// </summary>
Expand Down
15 changes: 1 addition & 14 deletions src/EFCore.Relational/Metadata/IReadOnlySequence.cs
Expand Up @@ -66,11 +66,6 @@ public interface IReadOnlySequence : IReadOnlyAnnotatable
/// </summary>
bool IsCyclic { get; }

/// <summary>
/// Gets the value indicating whether the sequence use preallocated values.
/// </summary>
bool IsCached { get; }

/// <summary>
/// Gets the amount of preallocated values, or <see langword="null" /> if none has been set.
/// </summary>
Expand Down Expand Up @@ -135,19 +130,11 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt
.Append(MaxValue);
}

if (!IsCached)
{
builder.Append(" No Cache");
}
else if (CacheSize != null)
if (CacheSize != null)
{
builder.Append(" Cache: ")
.Append(CacheSize);
}
else
{
builder.Append(" Cache");
}

if ((options & MetadataDebugStringOptions.SingleLine) == 0)
{
Expand Down
Expand Up @@ -198,8 +198,7 @@ public virtual bool CanSetIsCyclic(bool? cyclic, ConfigurationSource configurati
{
if (CanSetNoCache(configurationSource))
{
Metadata.SetIsCached(false, configurationSource);
Metadata.SetCacheSize(null, configurationSource);
Metadata.SetCacheSize(1, configurationSource);
return this;
}
return null;
Expand All @@ -212,8 +211,7 @@ public virtual bool CanSetIsCyclic(bool? cyclic, ConfigurationSource configurati
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool CanSetNoCache(ConfigurationSource configurationSource)
=> configurationSource.Overrides(Metadata.GetIsCachedConfigurationSource())
|| Metadata.IsCached == false;
=> configurationSource.Overrides(Metadata.GetCacheSizeConfigurationSource());

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -225,7 +223,6 @@ public virtual bool CanSetNoCache(ConfigurationSource configurationSource)
{
if (CanSetCacheSize(cacheSize, configurationSource))
{
Metadata.SetIsCached(true, configurationSource);
Metadata.SetCacheSize(cacheSize, configurationSource);
return this;
}
Expand Down