From 3b0bc7d5adfe7396e7d7385988519b3b8bd21a4a Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Fri, 21 Apr 2023 06:32:13 +0800 Subject: [PATCH] Fix the GetValueGenerated function. Was not being called and as such for an identity the ValueGenerated.OnAdd was not being set --- .../JetValueGeneratorConvention.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs b/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs index a5934c9..68883a2 100644 --- a/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs +++ b/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs @@ -5,6 +5,7 @@ using EntityFrameworkCore.Jet.Metadata.Internal; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +using System.Linq; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions @@ -60,25 +61,28 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// The store value generation strategy to set for the given property. protected override ValueGenerated? GetValueGenerated(IConventionProperty property) { - var tableName = property.DeclaringEntityType.GetTableName(); - if (tableName == null) + var declaringTable = property.GetMappedStoreObjects(StoreObjectType.Table).FirstOrDefault(); + if (declaringTable.Name == null) { return null; } - return GetValueGenerated(property, StoreObjectIdentifier.Table(tableName, property.DeclaringEntityType.GetSchema())); + // If the first mapping can be value generated then we'll consider all mappings to be value generated + // as this is a client-side configuration and can't be specified per-table. + return GetValueGenerated(property, declaringTable); } /// /// Returns the store value generation strategy to set for the given property. /// - /// The property. - /// The identifier of the store object. - /// The store value generation strategy to set for the given property. - public static ValueGenerated? GetValueGenerated([NotNull] IProperty property, in StoreObjectIdentifier storeObject) + /// The property. + /// The identifier of the store object. + /// The store value generation strategy to set for the given property. + public new static ValueGenerated? GetValueGenerated(IReadOnlyProperty property, in StoreObjectIdentifier storeObject) => RelationalValueGenerationConvention.GetValueGenerated(property, storeObject) - ?? (property.GetValueGenerationStrategy(storeObject) != JetValueGenerationStrategy.None - ? ValueGenerated.OnAdd - : (ValueGenerated?)null); + ?? (property.GetValueGenerationStrategy(storeObject) != JetValueGenerationStrategy.None + ? ValueGenerated.OnAdd + : null); + } } \ No newline at end of file