Skip to content

Commit

Permalink
First steps
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Jan 28, 2024
1 parent 6c96b0f commit d629a9d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,20 @@ public async Task RestartSequence()
};
var batch = await Generate(new[] { operation });
Assert.AreEqual(1, batch.Count());
Assert.AreEqual(NewLineEnd(@"ALTER SEQUENCE ""MySequence"" START WITH 23;"), batch[0].CommandText);
Assert.AreEqual(NewLineEnd(@"ALTER SEQUENCE ""MySequence"" RESTART WITH 23;"), batch[0].CommandText);
}

[Test]
public async Task RestartSequenceNoValue()
{
var operation = new RestartSequenceOperation()
{
Name = "MySequence",
StartValue = null,
};
var batch = await Generate(new[] { operation });
Assert.AreEqual(1, batch.Count());
Assert.AreEqual(NewLineEnd(@"ALTER SEQUENCE ""MySequence"" RESTART;"), batch[0].CommandText);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public static FbValueGenerationStrategy GetValueGenerationStrategy(this IPropert
return FbValueGenerationStrategy.None;
}

var modelStrategy = property.DeclaringEntityType.Model.GetValueGenerationStrategy();
var modelStrategy = property.DeclaringType.Model.GetValueGenerationStrategy();

if (modelStrategy == FbValueGenerationStrategy.SequenceTrigger && IsCompatibleSequenceTrigger(property))
{
return FbValueGenerationStrategy.SequenceTrigger;
}
if (modelStrategy == FbValueGenerationStrategy.IdentityColumn)
{
if (property.DeclaringEntityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
if (property.DeclaringType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
{
return FbValueGenerationStrategy.SequenceTrigger;
}
Expand Down Expand Up @@ -83,15 +83,15 @@ public static FbValueGenerationStrategy GetValueGenerationStrategy(this IMutable
return FbValueGenerationStrategy.None;
}

var modelStrategy = property.DeclaringEntityType.Model.GetValueGenerationStrategy();
var modelStrategy = property.DeclaringType.Model.GetValueGenerationStrategy();

if (modelStrategy == FbValueGenerationStrategy.SequenceTrigger && IsCompatibleSequenceTrigger(property))
{
return FbValueGenerationStrategy.SequenceTrigger;
}
if (modelStrategy == FbValueGenerationStrategy.IdentityColumn)
{
if (property.DeclaringEntityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
if (property.DeclaringType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
{
return FbValueGenerationStrategy.SequenceTrigger;
}
Expand Down Expand Up @@ -125,15 +125,15 @@ public static FbValueGenerationStrategy GetValueGenerationStrategy(this IConvent
return FbValueGenerationStrategy.None;
}

var modelStrategy = property.DeclaringEntityType.Model.GetValueGenerationStrategy();
var modelStrategy = property.DeclaringType.Model.GetValueGenerationStrategy();

if (modelStrategy == FbValueGenerationStrategy.SequenceTrigger && IsCompatibleSequenceTrigger(property))
{
return FbValueGenerationStrategy.SequenceTrigger;
}
if (modelStrategy == FbValueGenerationStrategy.IdentityColumn)
{
if (property.DeclaringEntityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
if (property.DeclaringType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy)
{
return FbValueGenerationStrategy.SequenceTrigger;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public static string SetHiLoSequenceSchema(this IConventionProperty property, st

public static IReadOnlySequence FindHiLoSequence(this IReadOnlyProperty property)
{
var model = property.DeclaringEntityType.Model;
var model = property.DeclaringType.Model;

var sequenceName = property.GetHiLoSequenceName()
?? model.GetHiLoSequenceName();
Expand All @@ -244,7 +244,7 @@ public static IReadOnlySequence FindHiLoSequence(this IReadOnlyProperty property

public static IReadOnlySequence FindHiLoSequence(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var model = property.DeclaringEntityType.Model;
var model = property.DeclaringType.Model;

var sequenceName = property.GetHiLoSequenceName(storeObject)
?? model.GetHiLoSequenceName();
Expand Down Expand Up @@ -329,7 +329,7 @@ public static string SetSequenceSchema(this IConventionProperty property, string

public static IReadOnlySequence FindSequence(this IReadOnlyProperty property)
{
var model = property.DeclaringEntityType.Model;
var model = property.DeclaringType.Model;

var sequenceName = property.GetSequenceName()
?? model.GetSequenceNameSuffix();
Expand All @@ -342,7 +342,7 @@ public static IReadOnlySequence FindSequence(this IReadOnlyProperty property)

public static IReadOnlySequence FindSequence(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var model = property.DeclaringEntityType.Model;
var model = property.DeclaringType.Model;

var sequenceName = property.GetSequenceName(storeObject)
?? model.GetSequenceNameSuffix();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>FirebirdSql.EntityFrameworkCore.Firebird</AssemblyName>
<RootNamespace>FirebirdSql.EntityFrameworkCore.Firebird</RootNamespace>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -29,7 +29,7 @@
<None Include="..\..\firebird-logo.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FirebirdSql.Data.FirebirdClient\FirebirdSql.Data.FirebirdClient.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,12 @@ protected override void Generate(RestartSequenceOperation operation, IModel mode
{
builder.Append("ALTER SEQUENCE ");
builder.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema));
builder.Append(" START WITH ");
builder.Append(operation.StartValue.ToString(CultureInfo.InvariantCulture));
builder.Append(" RESTART");
if (operation.StartValue != null)
{
builder.Append(" WITH ");
builder.Append(((long)operation.StartValue).ToString(CultureInfo.InvariantCulture));
};
TerminateStatement(builder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public FbValueGeneratorCache(ValueGeneratorCacheDependencies dependencies)

public virtual FbSequenceValueGeneratorState GetOrAddSequenceState(IProperty property, IRelationalConnection connection)
{
var tableIdentifier = StoreObjectIdentifier.Create(property.DeclaringEntityType, StoreObjectType.Table);
var tableIdentifier = StoreObjectIdentifier.Create(property.DeclaringType, StoreObjectType.Table);
var sequence = tableIdentifier != null
? property.FindHiLoSequence(tableIdentifier.Value)
: property.FindHiLoSequence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FbValueGeneratorSelector(ValueGeneratorSelectorDependencies dependencies,

public new virtual IFbValueGeneratorCache Cache => (IFbValueGeneratorCache)base.Cache;

public override ValueGenerator Select(IProperty property, IEntityType entityType)
public override ValueGenerator Select(IProperty property, ITypeBase entityType)
{
if (property.GetValueGeneratorFactory() != null
|| property.GetValueGenerationStrategy() != FbValueGenerationStrategy.HiLo)
Expand Down Expand Up @@ -87,10 +87,10 @@ public override ValueGenerator Select(IProperty property, IEntityType entityType

throw new ArgumentException(
CoreStrings.InvalidValueGeneratorFactoryProperty(
nameof(FbSequenceValueGeneratorFactory), property.Name, property.DeclaringEntityType.DisplayName()));
nameof(FbSequenceValueGeneratorFactory), property.Name, property.DeclaringType.DisplayName()));
}

protected override ValueGenerator FindForType(IProperty property, IEntityType entityType, Type clrType)
protected override ValueGenerator FindForType(IProperty property, ITypeBase entityType, Type clrType)
=> property.ClrType.UnwrapNullableType() == typeof(Guid)
? property.ValueGenerated == ValueGenerated.Never || property.GetDefaultValueSql() != null
? new TemporaryGuidValueGenerator()
Expand Down

0 comments on commit d629a9d

Please sign in to comment.