diff --git a/Directory.Build.props b/Directory.Build.props
index 6c5bd9986..cff76730e 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -13,7 +13,7 @@
Copyright 2022 © The Npgsql Development Team
Npgsql
- 7.0.0-preview.7
+ 7.0.0-rc.1
true
PostgreSQL
https://github.com/npgsql/efcore.pg
diff --git a/Directory.Packages.props b/Directory.Packages.props
index a6fb4bf67..853cccb09 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,7 +1,7 @@
- 7.0.0-preview.7.22376.2
- 7.0.0-preview.7.22375.6
+ 7.0.0-rc.1.22378.4
+ 7.0.0-rc.1.22374.4
7.0.0-preview.6
diff --git a/src/EFCore.PG/Design/Internal/NpgsqlAnnotationCodeGenerator.cs b/src/EFCore.PG/Design/Internal/NpgsqlAnnotationCodeGenerator.cs
index d816c3797..a3606de3b 100644
--- a/src/EFCore.PG/Design/Internal/NpgsqlAnnotationCodeGenerator.cs
+++ b/src/EFCore.PG/Design/Internal/NpgsqlAnnotationCodeGenerator.cs
@@ -8,96 +8,104 @@ public class NpgsqlAnnotationCodeGenerator : AnnotationCodeGenerator
{
#region MethodInfos
- private static readonly MethodInfo _modelHasPostgresExtensionMethodInfo1
+ private static readonly MethodInfo ModelHasPostgresExtensionMethodInfo1
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresExtension), typeof(ModelBuilder), typeof(string));
- private static readonly MethodInfo _modelHasPostgresExtensionMethodInfo2
+ private static readonly MethodInfo ModelHasPostgresExtensionMethodInfo2
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresExtension), typeof(ModelBuilder), typeof(string), typeof(string), typeof(string));
- private static readonly MethodInfo _modelHasPostgresEnumMethodInfo1
+ private static readonly MethodInfo ModelHasPostgresEnumMethodInfo1
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresEnum), typeof(ModelBuilder), typeof(string), typeof(string[]));
-
- private static readonly MethodInfo _modelHasPostgresEnumMethodInfo2
+
+ private static readonly MethodInfo ModelHasPostgresEnumMethodInfo2
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresEnum), typeof(ModelBuilder), typeof(string), typeof(string), typeof(string[]));
- private static readonly MethodInfo _modelHasPostgresRangeMethodInfo1
+ private static readonly MethodInfo ModelHasPostgresRangeMethodInfo1
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresRange), typeof(ModelBuilder), typeof(string), typeof(string));
-
- private static readonly MethodInfo _modelHasPostgresRangeMethodInfo2
+
+ private static readonly MethodInfo ModelHasPostgresRangeMethodInfo2
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.HasPostgresRange), typeof(ModelBuilder), typeof(string), typeof(string),typeof(string), typeof(string),typeof(string), typeof(string),typeof(string));
- private static readonly MethodInfo _modelUseSerialColumnsMethodInfo
+ private static readonly MethodInfo ModelUseSerialColumnsMethodInfo
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.UseSerialColumns), typeof(ModelBuilder));
- private static readonly MethodInfo _modelUseIdentityAlwaysColumnsMethodInfo
+ private static readonly MethodInfo ModelUseIdentityAlwaysColumnsMethodInfo
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.UseIdentityAlwaysColumns), typeof(ModelBuilder));
- private static readonly MethodInfo _modelUseIdentityByDefaultColumnsMethodInfo
+ private static readonly MethodInfo ModelUseIdentityByDefaultColumnsMethodInfo
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns), typeof(ModelBuilder));
- private static readonly MethodInfo _modelUseHiLoMethodInfo
+ private static readonly MethodInfo ModelUseHiLoMethodInfo
= typeof(NpgsqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlModelBuilderExtensions.UseHiLo), typeof(ModelBuilder), typeof(string), typeof(string));
- private static readonly MethodInfo _modelHasAnnotationMethodInfo
+ private static readonly MethodInfo ModelHasAnnotationMethodInfo
= typeof(ModelBuilder).GetRequiredRuntimeMethod(
nameof(ModelBuilder.HasAnnotation), typeof(string), typeof(object));
- private static readonly MethodInfo _entityTypeIsUnloggedMethodInfo
+ private static readonly MethodInfo ModelUseKeySequencesMethodInfo
+ = typeof(NpgsqlModelBuilderExtensions).GetRuntimeMethod(
+ nameof(NpgsqlModelBuilderExtensions.UseKeySequences), new[] { typeof(ModelBuilder), typeof(string), typeof(string) })!;
+
+ private static readonly MethodInfo EntityTypeIsUnloggedMethodInfo
= typeof(NpgsqlEntityTypeBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlEntityTypeBuilderExtensions.IsUnlogged), typeof(EntityTypeBuilder), typeof(bool));
- private static readonly MethodInfo _propertyUseSerialColumnMethodInfo
+ private static readonly MethodInfo PropertyUseSerialColumnMethodInfo
= typeof(NpgsqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlPropertyBuilderExtensions.UseSerialColumn), typeof(PropertyBuilder));
- private static readonly MethodInfo _propertyUseIdentityAlwaysColumnMethodInfo
+ private static readonly MethodInfo PropertyUseIdentityAlwaysColumnMethodInfo
= typeof(NpgsqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlPropertyBuilderExtensions.UseIdentityAlwaysColumn), typeof(PropertyBuilder));
- private static readonly MethodInfo _propertyUseIdentityByDefaultColumnMethodInfo
+ private static readonly MethodInfo PropertyUseIdentityByDefaultColumnMethodInfo
= typeof(NpgsqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn), typeof(PropertyBuilder));
- private static readonly MethodInfo _propertyUseHiLoMethodInfo
+ private static readonly MethodInfo PropertyUseHiLoMethodInfo
= typeof(NpgsqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlPropertyBuilderExtensions.UseHiLo), typeof(PropertyBuilder), typeof(string), typeof(string));
- private static readonly MethodInfo _propertyHasIdentityOptionsMethodInfo
+ private static readonly MethodInfo PropertyHasIdentityOptionsMethodInfo
= typeof(NpgsqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlPropertyBuilderExtensions.HasIdentityOptions), typeof(PropertyBuilder), typeof(long?), typeof(long?),
typeof(long?), typeof(long?), typeof(bool?), typeof(long?));
- private static readonly MethodInfo _indexUseCollationMethodInfo
+ private static readonly MethodInfo PropertyUseSequenceMethodInfo
+ = typeof(NpgsqlPropertyBuilderExtensions).GetRuntimeMethod(
+ nameof(NpgsqlPropertyBuilderExtensions.UseSequence), new[] { typeof(PropertyBuilder), typeof(string), typeof(string) })!;
+
+ private static readonly MethodInfo IndexUseCollationMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.UseCollation), typeof(IndexBuilder), typeof(string[]));
- private static readonly MethodInfo _indexHasMethodMethodInfo
+ private static readonly MethodInfo IndexHasMethodMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.HasMethod), typeof(IndexBuilder), typeof(string));
- private static readonly MethodInfo _indexHasOperatorsMethodInfo
+ private static readonly MethodInfo IndexHasOperatorsMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.HasOperators), typeof(IndexBuilder), typeof(string[]));
- private static readonly MethodInfo _indexHasSortOrderMethodInfo
+ private static readonly MethodInfo IndexHasSortOrderMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.HasSortOrder), typeof(IndexBuilder), typeof(SortOrder[]));
- private static readonly MethodInfo _indexHasNullSortOrderMethodInfo
+ private static readonly MethodInfo IndexHasNullSortOrderMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.HasNullSortOrder), typeof(IndexBuilder), typeof(NullSortOrder[]));
- private static readonly MethodInfo _indexIncludePropertiesMethodInfo
+ private static readonly MethodInfo IndexIncludePropertiesMethodInfo
= typeof(NpgsqlIndexBuilderExtensions).GetRequiredRuntimeMethod(
nameof(NpgsqlIndexBuilderExtensions.IncludeProperties), typeof(IndexBuilder), typeof(string[]));
@@ -161,9 +169,16 @@ protected override bool IsHandledByConvention(IProperty property, IAnnotation an
public override IReadOnlyList GenerateFluentApiCalls(
IModel model,
IDictionary annotations)
- => base.GenerateFluentApiCalls(model, annotations)
- .Concat(GenerateValueGenerationStrategy(annotations, onModel: true))
- .ToList();
+ {
+ var fragments = new List(base.GenerateFluentApiCalls(model, annotations));
+
+ if (GenerateValueGenerationStrategy(annotations, onModel: true) is { } valueGenerationStrategy)
+ {
+ fragments.Add(valueGenerationStrategy);
+ }
+
+ return fragments;
+ }
protected override MethodCallCodeFragment? GenerateFluentApi(IModel model, IAnnotation annotation)
{
@@ -175,8 +190,8 @@ public override IReadOnlyList GenerateFluentApiCalls(
var extension = new PostgresExtension(model, annotation.Name);
return extension.Schema is "public" or null
- ? new MethodCallCodeFragment(_modelHasPostgresExtensionMethodInfo1, extension.Name)
- : new MethodCallCodeFragment(_modelHasPostgresExtensionMethodInfo2, extension.Schema, extension.Name);
+ ? new MethodCallCodeFragment(ModelHasPostgresExtensionMethodInfo1, extension.Name)
+ : new MethodCallCodeFragment(ModelHasPostgresExtensionMethodInfo2, extension.Schema, extension.Name);
}
if (annotation.Name.StartsWith(NpgsqlAnnotationNames.EnumPrefix, StringComparison.Ordinal))
@@ -184,8 +199,8 @@ public override IReadOnlyList GenerateFluentApiCalls(
var enumTypeDef = new PostgresEnum(model, annotation.Name);
return enumTypeDef.Schema is null
- ? new MethodCallCodeFragment(_modelHasPostgresEnumMethodInfo1, enumTypeDef.Name, enumTypeDef.Labels)
- : new MethodCallCodeFragment(_modelHasPostgresEnumMethodInfo2, enumTypeDef.Schema, enumTypeDef.Name, enumTypeDef.Labels);
+ ? new MethodCallCodeFragment(ModelHasPostgresEnumMethodInfo1, enumTypeDef.Name, enumTypeDef.Labels)
+ : new MethodCallCodeFragment(ModelHasPostgresEnumMethodInfo2, enumTypeDef.Schema, enumTypeDef.Name, enumTypeDef.Labels);
}
if (annotation.Name.StartsWith(NpgsqlAnnotationNames.RangePrefix, StringComparison.Ordinal))
@@ -198,10 +213,10 @@ rangeTypeDef.SubtypeOpClass is null &&
rangeTypeDef.Collation is null &&
rangeTypeDef.SubtypeDiff is null)
{
- return new MethodCallCodeFragment(_modelHasPostgresRangeMethodInfo1, rangeTypeDef.Name, rangeTypeDef.Subtype);
+ return new MethodCallCodeFragment(ModelHasPostgresRangeMethodInfo1, rangeTypeDef.Name, rangeTypeDef.Subtype);
}
- return new MethodCallCodeFragment(_modelHasPostgresRangeMethodInfo2,
+ return new MethodCallCodeFragment(ModelHasPostgresRangeMethodInfo2,
rangeTypeDef.Schema,
rangeTypeDef.Name,
rangeTypeDef.Subtype,
@@ -221,7 +236,7 @@ rangeTypeDef.Collation is null &&
if (annotation.Name == NpgsqlAnnotationNames.UnloggedTable)
{
- return new MethodCallCodeFragment(_entityTypeIsUnloggedMethodInfo, annotation.Value);
+ return new MethodCallCodeFragment(EntityTypeIsUnloggedMethodInfo, annotation.Value);
}
return null;
@@ -230,61 +245,71 @@ rangeTypeDef.Collation is null &&
public override IReadOnlyList GenerateFluentApiCalls(
IProperty property,
IDictionary annotations)
- => base.GenerateFluentApiCalls(property, annotations)
- .Concat(GenerateValueGenerationStrategy(annotations, onModel: false))
- .Concat(GenerateIdentityOptions(annotations))
- .ToList();
+ {
+ var fragments = new List(base.GenerateFluentApiCalls(property, annotations));
- private IReadOnlyList GenerateValueGenerationStrategy(
- IDictionary annotations,
- bool onModel)
+ if (GenerateValueGenerationStrategy(annotations, onModel: false) is { } valueGenerationStrategy)
+ {
+ fragments.Add(valueGenerationStrategy);
+ }
+
+ if (GenerateIdentityOptions(annotations) is { } identityOptionsFragment)
+ {
+ fragments.Add(identityOptionsFragment);
+ }
+
+ return fragments;
+ }
+
+ private MethodCallCodeFragment? GenerateValueGenerationStrategy(IDictionary annotations, bool onModel)
{
- if (!TryGetAndRemove(annotations, NpgsqlAnnotationNames.ValueGenerationStrategy,
- out NpgsqlValueGenerationStrategy strategy))
+ if (!TryGetAndRemove(annotations, NpgsqlAnnotationNames.ValueGenerationStrategy, out NpgsqlValueGenerationStrategy strategy))
{
- return Array.Empty();
+ return null;
}
switch (strategy)
{
case NpgsqlValueGenerationStrategy.SerialColumn:
- return new List
- {
- new(onModel ? _modelUseSerialColumnsMethodInfo : _propertyUseSerialColumnMethodInfo)
- };
+ return new(onModel ? ModelUseSerialColumnsMethodInfo : PropertyUseSerialColumnMethodInfo);
case NpgsqlValueGenerationStrategy.IdentityAlwaysColumn:
- return new List
- {
- new(onModel ? _modelUseIdentityAlwaysColumnsMethodInfo : _propertyUseIdentityAlwaysColumnMethodInfo)
- };
+ return new(onModel ? ModelUseIdentityAlwaysColumnsMethodInfo : PropertyUseIdentityAlwaysColumnMethodInfo);
case NpgsqlValueGenerationStrategy.IdentityByDefaultColumn:
- return new List
- {
- new(onModel ? _modelUseIdentityByDefaultColumnsMethodInfo : _propertyUseIdentityByDefaultColumnMethodInfo)
- };
+ return new(onModel ? ModelUseIdentityByDefaultColumnsMethodInfo : PropertyUseIdentityByDefaultColumnMethodInfo);
case NpgsqlValueGenerationStrategy.SequenceHiLo:
+ {
var name = GetAndRemove(NpgsqlAnnotationNames.HiLoSequenceName)!;
var schema = GetAndRemove(NpgsqlAnnotationNames.HiLoSequenceSchema);
- return new List
- {
- new(
- onModel ? _modelUseHiLoMethodInfo : _propertyUseHiLoMethodInfo,
- (name, schema) switch
- {
- (null, null) => Array.Empty