From b8ad9acde83829477e76e5d3d0c16453f840af49 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 03:06:31 +0000 Subject: [PATCH 1/9] Initial plan From 708a5621fb27f515e78c54d9fd141ef04506a12e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 03:20:56 +0000 Subject: [PATCH 2/9] Add compiled model provider mismatch warning infrastructure - Add ProviderName property to DbContextModelAttribute - Add CompiledModelProviderMismatchWarning event ID to CoreEventId - Add warning message to CoreStrings.resx and Designer.cs - Add LogCompiledModelProviderMismatch field to LoggingDefinitions - Add logger extension method CompiledModelProviderMismatchWarning - Update FindCompiledModel to check provider name and skip mismatched models - Add ProviderName to CompiledModelCodeGenerationOptions - Update DbContextOperations to set ProviderName from IDatabaseProvider - Update CSharpRuntimeModelCodeGenerator to emit ProviderName in attribute Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Design/Internal/DbContextOperations.cs | 2 ++ .../CompiledModelCodeGenerationOptions.cs | 6 +++++ .../CSharpRuntimeModelCodeGenerator.cs | 13 ++++++++-- src/EFCore/Diagnostics/CoreEventId.cs | 14 +++++++++++ .../Diagnostics/CoreLoggerExtensions.cs | 22 ++++++++++++++++ src/EFCore/Diagnostics/LoggingDefinitions.cs | 9 +++++++ .../Infrastructure/DbContextModelAttribute.cs | 5 ++++ src/EFCore/Internal/DbContextServices.cs | 25 +++++++++++++++++-- src/EFCore/Properties/CoreStrings.Designer.cs | 25 +++++++++++++++++++ src/EFCore/Properties/CoreStrings.resx | 4 +++ 10 files changed, 121 insertions(+), 4 deletions(-) diff --git a/src/EFCore.Design/Design/Internal/DbContextOperations.cs b/src/EFCore.Design/Design/Internal/DbContextOperations.cs index a574248918d..78a3bcb808d 100644 --- a/src/EFCore.Design/Design/Internal/DbContextOperations.cs +++ b/src/EFCore.Design/Design/Internal/DbContextOperations.cs @@ -259,6 +259,7 @@ private IReadOnlyList ScaffoldCompiledModel( outputDir = Path.GetFullPath(Path.Combine(_projectDir, outputDir)); var scaffolder = services.GetRequiredService(); + var databaseProvider = context.GetService(); var finalModelNamespace = modelNamespace ?? GetNamespaceFromOutputPath(outputDir) ?? ""; @@ -273,6 +274,7 @@ private IReadOnlyList ScaffoldCompiledModel( UseNullableReferenceTypes = _nullable, Suffix = suffix, ForNativeAot = nativeAot, + ProviderName = databaseProvider.Name, GeneratedFileNames = generatedFileNames }); diff --git a/src/EFCore.Design/Scaffolding/CompiledModelCodeGenerationOptions.cs b/src/EFCore.Design/Scaffolding/CompiledModelCodeGenerationOptions.cs index 74774ea74dc..8b666b3a9a5 100644 --- a/src/EFCore.Design/Scaffolding/CompiledModelCodeGenerationOptions.cs +++ b/src/EFCore.Design/Scaffolding/CompiledModelCodeGenerationOptions.cs @@ -44,6 +44,12 @@ public class CompiledModelCodeGenerationOptions /// A value indicating whether the generated code should be compatible with NativeAOT. public virtual bool ForNativeAot { get; set; } + /// + /// Gets or sets the database provider name to embed in the compiled model. + /// + /// The database provider name. + public virtual string? ProviderName { get; set; } + /// /// Gets or sets the set of file names generated so far. /// diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs index b02f95d8df4..70e7775f09e 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs @@ -66,7 +66,7 @@ public virtual IReadOnlyCollection GenerateModel( var nullable = false; var scaffoldedFiles = new List(); - var assemblyAttributesCode = CreateAssemblyAttributes(options.ModelNamespace, options.ContextType, nullable); + var assemblyAttributesCode = CreateAssemblyAttributes(options.ModelNamespace, options.ContextType, options.ProviderName, nullable); var assemblyInfoFileName = UniquifyFileName(options.ContextType.ShortDisplayName() + AssemblyAttributesSuffix, options); scaffoldedFiles.Add(new ScaffoldedFile(assemblyInfoFileName, assemblyAttributesCode)); @@ -174,6 +174,7 @@ private static string GenerateHeader(SortedSet namespaces, string curren private string CreateAssemblyAttributes( string @namespace, Type contextType, + string? providerName, bool nullable) { var mainBuilder = new IndentedStringBuilder(); @@ -183,7 +184,15 @@ private string CreateAssemblyAttributes( mainBuilder .Append("[assembly: DbContextModel(typeof(").Append(_code.Reference(contextType)) - .Append("), typeof(").Append(GetModelClassName(contextType)).AppendLine("))]"); + .Append("), typeof(").Append(GetModelClassName(contextType)).Append(")"); + + if (providerName != null) + { + mainBuilder + .Append(", ProviderName = ").Append(_code.Literal(providerName)); + } + + mainBuilder.AppendLine(")]"); return GenerateHeader(namespaces, currentNamespace: "", nullable) + mainBuilder; } diff --git a/src/EFCore/Diagnostics/CoreEventId.cs b/src/EFCore/Diagnostics/CoreEventId.cs index 3ccfac94727..717abcdb16c 100644 --- a/src/EFCore/Diagnostics/CoreEventId.cs +++ b/src/EFCore/Diagnostics/CoreEventId.cs @@ -90,6 +90,7 @@ private enum Id ServiceProviderDebugInfo, RedundantAddServicesCallWarning, OldModelVersionWarning, + CompiledModelProviderMismatchWarning, // Model and ModelValidation events ShadowPropertyCreated = CoreBaseId + 600, @@ -491,6 +492,19 @@ private static EventId MakeInfraId(Id id) /// public static readonly EventId OldModelVersionWarning = MakeInfraId(Id.OldModelVersionWarning); + /// + /// A compiled model was found but was built for a different database provider. + /// + /// + /// + /// This event is in the category. + /// + /// + /// This event uses the payload when used with a . + /// + /// + public static readonly EventId CompiledModelProviderMismatchWarning = MakeInfraId(Id.CompiledModelProviderMismatchWarning); + private static readonly string _modelPrefix = DbLoggerCategory.Model.Name + "."; private static EventId MakeModelId(Id id) diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index 5054434a5ba..a8c1411afd8 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -230,6 +230,28 @@ private static string OldModelVersion(EventDefinitionBase definition, EventData ProductInfo.GetVersion()); } + /// + /// Logs for the event. + /// + /// The diagnostics logger to use. + /// The provider name stored in the compiled model. + /// The provider name currently configured. + public static void CompiledModelProviderMismatchWarning( + this IDiagnosticsLogger diagnostics, + string compiledProviderName, + string currentProviderName) + { + var definition = CoreResources.LogCompiledModelProviderMismatch(diagnostics); + + if (diagnostics.ShouldLog(definition)) + { + definition.Log( + diagnostics, + compiledProviderName, + currentProviderName); + } + } + /// /// Logs for the event. /// diff --git a/src/EFCore/Diagnostics/LoggingDefinitions.cs b/src/EFCore/Diagnostics/LoggingDefinitions.cs index 04145a1fed6..30b462e0aae 100644 --- a/src/EFCore/Diagnostics/LoggingDefinitions.cs +++ b/src/EFCore/Diagnostics/LoggingDefinitions.cs @@ -106,6 +106,15 @@ public abstract class LoggingDefinitions [EntityFrameworkInternal] public EventDefinitionBase? LogOldModelVersion; + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + [EntityFrameworkInternal] + public EventDefinitionBase? LogCompiledModelProviderMismatch; + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore/Infrastructure/DbContextModelAttribute.cs b/src/EFCore/Infrastructure/DbContextModelAttribute.cs index bebeb262a0c..553c83f0034 100644 --- a/src/EFCore/Infrastructure/DbContextModelAttribute.cs +++ b/src/EFCore/Infrastructure/DbContextModelAttribute.cs @@ -41,4 +41,9 @@ public DbContextModelAttribute( /// Gets the compiled model. /// public Type ModelType { get; } + + /// + /// Gets the database provider name used to build the compiled model. + /// + public string? ProviderName { get; set; } } diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs index cd9b61b29d6..5c7c4bf2ec3 100644 --- a/src/EFCore/Internal/DbContextServices.cs +++ b/src/EFCore/Internal/DbContextServices.cs @@ -67,7 +67,19 @@ private IModel CreateModel(bool designTime) _inOnModelCreating = true; var dependencies = _scopedProvider!.GetRequiredService(); - var modelFromOptions = CoreOptions?.Model ?? FindCompiledModel(_currentContext!.Context.GetType()); + + var providers = _scopedProvider!.GetService>()?.ToList(); + var providerName = providers is [var provider] ? provider.Name : null; + + string? mismatchedProviderName = null; + var modelFromOptions = CoreOptions?.Model + ?? FindCompiledModel(_currentContext!.Context.GetType(), providerName, out mismatchedProviderName); + + if (mismatchedProviderName != null) + { + var logger = _scopedProvider!.GetRequiredService>(); + logger.CompiledModelProviderMismatchWarning(mismatchedProviderName, providerName!); + } var modelVersion = modelFromOptions?.GetProductVersion(); if (modelVersion != null) @@ -105,8 +117,9 @@ private IModel CreateModel(bool designTime) _inOnModelCreating = false; } - static IModel? FindCompiledModel(Type contextType) + static IModel? FindCompiledModel(Type contextType, string? providerName, out string? mismatchedProviderName) { + mismatchedProviderName = null; var contextAssembly = contextType.Assembly; IModel? model = null; foreach (var modelAttribute in contextAssembly.GetCustomAttributes()) @@ -116,6 +129,14 @@ private IModel CreateModel(bool designTime) continue; } + if (modelAttribute.ProviderName != null + && providerName != null + && modelAttribute.ProviderName != providerName) + { + mismatchedProviderName = modelAttribute.ProviderName; + continue; + } + var modelType = modelAttribute.ModelType; var instanceProperty = modelType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 491e64911ba..814ad895a05 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -4722,6 +4722,31 @@ public static EventDefinition LogOldModelVersion(IDiagnosticsLog return (EventDefinition)definition; } + /// + /// A compiled model was found but was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Update the compiled model to use the correct provider. + /// + public static EventDefinition LogCompiledModelProviderMismatch(IDiagnosticsLogger logger) + { + var definition = ((LoggingDefinitions)logger.Definitions).LogCompiledModelProviderMismatch; + if (definition == null) + { + definition = NonCapturingLazyInitializer.EnsureInitialized( + ref ((LoggingDefinitions)logger.Definitions).LogCompiledModelProviderMismatch, + logger, + static logger => new EventDefinition( + logger.Options, + CoreEventId.CompiledModelProviderMismatchWarning, + LogLevel.Warning, + "CoreEventId.CompiledModelProviderMismatchWarning", + level => LoggerMessage.Define( + level, + CoreEventId.CompiledModelProviderMismatchWarning, + _resourceManager.GetString("LogCompiledModelProviderMismatch")!))); + } + + return (EventDefinition)definition; + } + /// /// {error} /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 7c363a7b47f..7bcb9b5372b 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1068,6 +1068,10 @@ The model supplied in the context options was created with EF Core version '{oldVersion}', but the context is from version '{newVersion}'. Update the externally built model. Warning CoreEventId.OldModelVersionWarning string string + + A compiled model was found but was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Update the compiled model to use the correct provider. + Warning CoreEventId.CompiledModelProviderMismatchWarning string string + {error} Debug CoreEventId.OptimisticConcurrencyException Exception From e91316071e75e8dfa84ef70cba8fea40400532b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 03:35:26 +0000 Subject: [PATCH 3/9] Update compiled model test baselines and add provider mismatch tests - Update all 42 baseline DbContextAssemblyAttributes.cs files to include ProviderName - Set ProviderName in CompiledModelTestBase.Test() method - Add tests for provider mismatch warning message format and attribute behavior Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../DbContextAssemblyAttributes.cs | 2 +- .../BigModel/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../BigModel/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- ...lobalNamespaceContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../Scaffolding/CompiledModelTestBase.cs | 1 + .../BigModel/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../Sequences/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../Tpc_Sprocs/DbContextAssemblyAttributes.cs | 2 +- .../Triggers/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../BigModel/DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../DbContextAssemblyAttributes.cs | 2 +- .../Triggers/DbContextAssemblyAttributes.cs | 2 +- .../Infrastructure/ModelSourceTest.cs | 31 +++++++++++++++++++ 45 files changed, 75 insertions(+), 43 deletions(-) diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Basic_cosmos_model/DbContextAssemblyAttributes.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Basic_cosmos_model/DbContextAssemblyAttributes.cs index c224873f6fa..b71e4f5f111 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Basic_cosmos_model/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Basic_cosmos_model/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Cosmos")] diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs index c224873f6fa..b71e4f5f111 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Cosmos")] diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs index c224873f6fa..b71e4f5f111 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Cosmos")] diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs index c224873f6fa..b71e4f5f111 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Cosmos")] diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs index c224873f6fa..b71e4f5f111 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Cosmos")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_provider_value_comparer/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_provider_value_comparer/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_provider_value_comparer/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_provider_value_comparer/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_type_mapping/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_type_mapping/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_type_mapping/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_type_mapping/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_comparer/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_comparer/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_comparer/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_comparer/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_converter/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_converter/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_converter/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Custom_value_converter/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Empty_model/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Empty_model/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Empty_model/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Empty_model/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Fully_qualified_model/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Fully_qualified_model/DbContextAssemblyAttributes.cs index 3879ce8f4f5..9793f9522ba 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Fully_qualified_model/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Fully_qualified_model/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Global_namespace/GlobalNamespaceContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Global_namespace/GlobalNamespaceContextAssemblyAttributes.cs index 5a2d96f9853..cfd694ba828 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Global_namespace/GlobalNamespaceContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Global_namespace/GlobalNamespaceContextAssemblyAttributes.cs @@ -4,4 +4,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(GlobalNamespaceContext), typeof(GlobalNamespaceContextModel))] +[assembly: DbContextModel(typeof(GlobalNamespaceContext), typeof(GlobalNamespaceContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_manual/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_manual/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_manual/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_manual/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_proxies/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_proxies/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_proxies/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Lazy_loading_proxies/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Manual_lazy_loading/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Manual_lazy_loading/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Manual_lazy_loading/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Manual_lazy_loading/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/RelationshipCycles/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/RelationshipCycles/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/RelationshipCycles/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/RelationshipCycles/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Self_referential_property/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Self_referential_property/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Self_referential_property/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/Self_referential_property/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs index c224873f6fa..c32d233bbdb 100644 --- a/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] diff --git a/test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs b/test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs index 6db059e5fe1..4131d897023 100644 --- a/test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs +++ b/test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs @@ -2087,6 +2087,7 @@ protected virtual Task Test( options ??= new CompiledModelCodeGenerationOptions { ForNativeAot = true }; options.ModelNamespace ??= "TestNamespace"; options.ContextType ??= context.GetType(); + options.ProviderName ??= context.GetService().Name; var generator = TestHelpers.CreateDesignServiceProvider( context.GetService().Name, diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Full_text_index/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Full_text_index/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Full_text_index/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Full_text_index/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_HiLo_sequence/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_HiLo_sequence/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_HiLo_sequence/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_HiLo_sequence/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_sequence/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_sequence/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_sequence/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Key_sequence/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Sequences/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Sequences/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Sequences/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Sequences/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SpatialTypesTest/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SpatialTypesTest/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SpatialTypesTest/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/SpatialTypesTest/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Tpc_Sprocs/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Tpc_Sprocs/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Tpc_Sprocs/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Tpc_Sprocs/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Vector_index/DbContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Vector_index/DbContextAssemblyAttributes.cs index c224873f6fa..6a0ec176019 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Vector_index/DbContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Vector_index/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/CheckConstraints/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Dynamic_schema/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/SimpleModel/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs index c224873f6fa..43d296d89f6 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Triggers/DbContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel))] +[assembly: DbContextModel(typeof(DbContext), typeof(DbContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Tests/Infrastructure/ModelSourceTest.cs b/test/EFCore.Tests/Infrastructure/ModelSourceTest.cs index 0011ae8f6a8..3fb099a22d9 100644 --- a/test/EFCore.Tests/Infrastructure/ModelSourceTest.cs +++ b/test/EFCore.Tests/Infrastructure/ModelSourceTest.cs @@ -266,6 +266,37 @@ protected internal override void OnModelCreating(ModelBuilder modelBuilder) private class Context2(DbContextOptions options) : DbContext(options); + [ConditionalFact] + public void Compiled_model_provider_mismatch_warning_has_correct_message() + { + var definition = CoreResources.LogCompiledModelProviderMismatch( + new TestLogger()); + + var message = definition.GenerateMessage("Microsoft.EntityFrameworkCore.SqlServer", "Microsoft.EntityFrameworkCore.InMemory"); + + Assert.Contains("Microsoft.EntityFrameworkCore.SqlServer", message); + Assert.Contains("Microsoft.EntityFrameworkCore.InMemory", message); + } + + [ConditionalFact] + public void DbContextModelAttribute_stores_provider_name() + { + var attr = new DbContextModelAttribute(typeof(DbContext), typeof(object)) + { + ProviderName = "TestProvider" + }; + + Assert.Equal("TestProvider", attr.ProviderName); + } + + [ConditionalFact] + public void DbContextModelAttribute_provider_name_defaults_to_null() + { + var attr = new DbContextModelAttribute(typeof(DbContext), typeof(object)); + + Assert.Null(attr.ProviderName); + } + private class DetailedErrorsContext(IServiceProvider serviceProvider) : DbContext { private readonly IServiceProvider _serviceProvider = serviceProvider; From d6e3c983fe26b551a697d49a46f03daa3c2a40b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 03:36:38 +0000 Subject: [PATCH 4/9] Fix remaining 6 baseline files with custom context types Update DbFunctions, Custom_function_type_mapping, and Custom_function_parameter_type_mapping baselines for SQLite and SqlServer Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../FunctionParameterTypeMappingContextAssemblyAttributes.cs | 2 +- .../FunctionTypeMappingContextAssemblyAttributes.cs | 2 +- .../DbFunctions/DbFunctionContextAssemblyAttributes.cs | 2 +- .../FunctionParameterTypeMappingContextAssemblyAttributes.cs | 2 +- .../FunctionTypeMappingContextAssemblyAttributes.cs | 2 +- .../DbFunctions/DbFunctionContextAssemblyAttributes.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs index 188db7938f6..370f8aa43ad 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionParameterTypeMappingContext), typeof(FunctionParameterTypeMappingContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionParameterTypeMappingContext), typeof(FunctionParameterTypeMappingContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs index 7ab16249c50..25d807e86b9 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionTypeMappingContext), typeof(FunctionTypeMappingContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionTypeMappingContext), typeof(FunctionTypeMappingContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs index a248efefdc0..feed600ccec 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.DbFunctionContext), typeof(DbFunctionContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.DbFunctionContext), typeof(DbFunctionContextModel), ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs index 188db7938f6..07e942e8bf0 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_parameter_type_mapping/FunctionParameterTypeMappingContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionParameterTypeMappingContext), typeof(FunctionParameterTypeMappingContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionParameterTypeMappingContext), typeof(FunctionParameterTypeMappingContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs index 7ab16249c50..991b940cd2a 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/Custom_function_type_mapping/FunctionTypeMappingContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionTypeMappingContext), typeof(FunctionTypeMappingContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.FunctionTypeMappingContext), typeof(FunctionTypeMappingContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs index a248efefdc0..353ec8730f2 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/DbFunctions/DbFunctionContextAssemblyAttributes.cs @@ -6,4 +6,4 @@ #pragma warning disable 219, 612, 618 #nullable disable -[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.DbFunctionContext), typeof(DbFunctionContextModel))] +[assembly: DbContextModel(typeof(CompiledModelRelationalTestBase.DbFunctionContext), typeof(DbFunctionContextModel), ProviderName = "Microsoft.EntityFrameworkCore.Sqlite")] From 0916efdb8454b8d96e128df7aa22c4936b8e063a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 05:15:32 +0000 Subject: [PATCH 5/9] Move provider name calculation inside CoreOptions?.Model null check Only resolve IDatabaseProvider and calculate provider name when CoreOptions?.Model is null, avoiding unnecessary work when the model is already provided via context options. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- src/EFCore/Internal/DbContextServices.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs index 5c7c4bf2ec3..8876a12ee35 100644 --- a/src/EFCore/Internal/DbContextServices.cs +++ b/src/EFCore/Internal/DbContextServices.cs @@ -68,17 +68,20 @@ private IModel CreateModel(bool designTime) var dependencies = _scopedProvider!.GetRequiredService(); - var providers = _scopedProvider!.GetService>()?.ToList(); - var providerName = providers is [var provider] ? provider.Name : null; - string? mismatchedProviderName = null; - var modelFromOptions = CoreOptions?.Model - ?? FindCompiledModel(_currentContext!.Context.GetType(), providerName, out mismatchedProviderName); - - if (mismatchedProviderName != null) + var modelFromOptions = CoreOptions?.Model; + if (modelFromOptions == null) { - var logger = _scopedProvider!.GetRequiredService>(); - logger.CompiledModelProviderMismatchWarning(mismatchedProviderName, providerName!); + var providers = _scopedProvider!.GetService>()?.ToList(); + var providerName = providers is [var provider] ? provider.Name : null; + + modelFromOptions = FindCompiledModel(_currentContext!.Context.GetType(), providerName, out mismatchedProviderName); + + if (mismatchedProviderName != null) + { + var logger = _scopedProvider!.GetRequiredService>(); + logger.CompiledModelProviderMismatchWarning(mismatchedProviderName, providerName!); + } } var modelVersion = modelFromOptions?.GetProductVersion(); From cd2673e8d402d29d5e55be09384e15ae2d439127 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 19:27:07 +0000 Subject: [PATCH 6/9] Fix event dispatch and update warning message text Add NeedsEventData/DispatchEventData block to CompiledModelProviderMismatchWarning so the event is properly dispatched to DiagnosticSource and IDbContextLogger. Update warning message text per review feedback. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- src/EFCore/Diagnostics/CoreLoggerExtensions.cs | 9 +++++++++ src/EFCore/Properties/CoreStrings.resx | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index a8c1411afd8..47af2d7633e 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -250,6 +250,15 @@ public static void CompiledModelProviderMismatchWarning( compiledProviderName, currentProviderName); } + + if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled)) + { + var eventData = new EventData( + definition, + (d, _) => ((EventDefinition)d).GenerateMessage(compiledProviderName, currentProviderName)); + + diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled); + } } /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 7bcb9b5372b..edd710d181f 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1069,7 +1069,7 @@ Warning CoreEventId.OldModelVersionWarning string string - A compiled model was found but was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Update the compiled model to use the correct provider. + A compiled model was found but it was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Regenerate the compiled model with the correct provider. Warning CoreEventId.CompiledModelProviderMismatchWarning string string From 9d3acd40854b8ed24075986206f06685e2d65d89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 20:54:22 +0000 Subject: [PATCH 7/9] Add CompiledModelProviderMismatchEventData and refactor FindCompiledModel logic Create dedicated EventData subclass with static lambda for consistent event dispatch. Refactor FindCompiledModel to find matching/null provider first and only warn if no matching compiled model is found. Add end-to-end tests for provider mismatch warning and multi-provider selection. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../CompiledModelProviderMismatchEventData.cs | 41 ++++++ .../Diagnostics/CoreLoggerExtensions.cs | 13 +- src/EFCore/Internal/DbContextServices.cs | 8 +- .../CompiledModelProviderMismatchTest.cs | 133 ++++++++++++++++++ 4 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs create mode 100644 test/EFCore.Tests/Infrastructure/CompiledModelProviderMismatchTest.cs diff --git a/src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs b/src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs new file mode 100644 index 00000000000..c602e7040a3 --- /dev/null +++ b/src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.Diagnostics; + +/// +/// A event payload class for compiled model provider mismatch warnings. +/// +/// +/// See Logging, events, and diagnostics for more information and examples. +/// +public class CompiledModelProviderMismatchEventData : EventData +{ + /// + /// Constructs the event payload. + /// + /// The event definition. + /// A delegate that generates a log message for this event. + /// The provider name stored in the compiled model. + /// The provider name currently configured. + public CompiledModelProviderMismatchEventData( + EventDefinitionBase eventDefinition, + Func messageGenerator, + string compiledProviderName, + string currentProviderName) + : base(eventDefinition, messageGenerator) + { + CompiledProviderName = compiledProviderName; + CurrentProviderName = currentProviderName; + } + + /// + /// The provider name stored in the compiled model. + /// + public virtual string CompiledProviderName { get; } + + /// + /// The provider name currently configured. + /// + public virtual string CurrentProviderName { get; } +} diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index 47af2d7633e..1965c3bcf82 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -253,14 +253,23 @@ public static void CompiledModelProviderMismatchWarning( if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled)) { - var eventData = new EventData( + var eventData = new CompiledModelProviderMismatchEventData( definition, - (d, _) => ((EventDefinition)d).GenerateMessage(compiledProviderName, currentProviderName)); + CompiledModelProviderMismatch, + compiledProviderName, + currentProviderName); diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled); } } + private static string CompiledModelProviderMismatch(EventDefinitionBase definition, EventData payload) + { + var d = (EventDefinition)definition; + var p = (CompiledModelProviderMismatchEventData)payload; + return d.GenerateMessage(p.CompiledProviderName, p.CurrentProviderName); + } + /// /// Logs for the event. /// diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs index 8876a12ee35..dfd67f8da3c 100644 --- a/src/EFCore/Internal/DbContextServices.cs +++ b/src/EFCore/Internal/DbContextServices.cs @@ -125,6 +125,7 @@ private IModel CreateModel(bool designTime) mismatchedProviderName = null; var contextAssembly = contextType.Assembly; IModel? model = null; + string? firstMismatchedProvider = null; foreach (var modelAttribute in contextAssembly.GetCustomAttributes()) { if (modelAttribute.ContextType != contextType) @@ -136,7 +137,7 @@ private IModel CreateModel(bool designTime) && providerName != null && modelAttribute.ProviderName != providerName) { - mismatchedProviderName = modelAttribute.ProviderName; + firstMismatchedProvider ??= modelAttribute.ProviderName; continue; } @@ -159,6 +160,11 @@ private IModel CreateModel(bool designTime) model = (IModel)instanceProperty.GetValue(null)!; } + if (model == null) + { + mismatchedProviderName = firstMismatchedProvider; + } + return model; } } diff --git a/test/EFCore.Tests/Infrastructure/CompiledModelProviderMismatchTest.cs b/test/EFCore.Tests/Infrastructure/CompiledModelProviderMismatchTest.cs new file mode 100644 index 00000000000..f3a9014d031 --- /dev/null +++ b/test/EFCore.Tests/Infrastructure/CompiledModelProviderMismatchTest.cs @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Diagnostics.Internal; +using Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.TestUtilities; + +[assembly: DbContextModel( + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.MismatchedProviderContext), + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.MismatchedProviderTestModel), + ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] + +[assembly: DbContextModel( + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.MultiProviderContext), + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.WrongProviderTestModel), + ProviderName = "Microsoft.EntityFrameworkCore.SqlServer")] +[assembly: DbContextModel( + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.MultiProviderContext), + typeof(Microsoft.EntityFrameworkCore.Infrastructure.CompiledModelProviderMismatchTest.CorrectProviderTestModel), + ProviderName = "Microsoft.EntityFrameworkCore.InMemory")] + +// ReSharper disable InconsistentNaming +namespace Microsoft.EntityFrameworkCore.Infrastructure; + +public class CompiledModelProviderMismatchTest +{ + [ConditionalFact] + public void Compiled_model_with_mismatched_provider_is_skipped_and_warning_is_logged() + { + var serviceProvider = new ServiceCollection() + .AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(validateScopes: true); + + var context = new MismatchedProviderContext(serviceProvider); + var warning = CoreStrings.WarningAsErrorTemplate( + CoreEventId.CompiledModelProviderMismatchWarning, + CoreResources.LogCompiledModelProviderMismatch( + new TestLogger()).GenerateMessage( + "Microsoft.EntityFrameworkCore.SqlServer", "Microsoft.EntityFrameworkCore.InMemory"), + "CoreEventId.CompiledModelProviderMismatchWarning"); + + Assert.Equal( + warning, + Assert.Throws(() => context.Model).Message); + } + + [ConditionalFact] + public void Compiled_model_with_matching_provider_is_used_when_multiple_attributes_exist() + { + var serviceProvider = new ServiceCollection() + .AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(validateScopes: true); + + using var context = new MultiProviderContext(serviceProvider); + var model = context.Model; + + Assert.NotNull(model); + Assert.Same(CorrectProviderTestModel.Instance, model); + } + + public class MismatchedProviderContext(IServiceProvider serviceProvider) : DbContext + { + private readonly IServiceProvider _serviceProvider = serviceProvider; + + protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder + .UseInternalServiceProvider(_serviceProvider) + .UseInMemoryDatabase(nameof(MismatchedProviderContext)) + .ConfigureWarnings(w => w.Default(WarningBehavior.Throw)); + } + + public class MultiProviderContext(IServiceProvider serviceProvider) : DbContext + { + private readonly IServiceProvider _serviceProvider = serviceProvider; + + protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder + .UseInternalServiceProvider(_serviceProvider) + .UseInMemoryDatabase(nameof(MultiProviderContext)) + .ConfigureWarnings(w => w.Default(WarningBehavior.Throw)); + } + + public class MismatchedProviderTestModel + { + private static readonly RuntimeModel _instance = CreateModel(); + + public static IModel Instance + => _instance; + + private static RuntimeModel CreateModel() + { +#pragma warning disable CS0618 // Type or member is obsolete + var model = new RuntimeModel(); +#pragma warning restore CS0618 + model.AddAnnotation(CoreAnnotationNames.ProductVersion, ProductInfo.GetVersion()); + return model; + } + } + + public class WrongProviderTestModel + { + private static readonly RuntimeModel _instance = CreateModel(); + + public static IModel Instance + => _instance; + + private static RuntimeModel CreateModel() + { +#pragma warning disable CS0618 // Type or member is obsolete + var model = new RuntimeModel(); +#pragma warning restore CS0618 + model.AddAnnotation(CoreAnnotationNames.ProductVersion, ProductInfo.GetVersion()); + return model; + } + } + + public class CorrectProviderTestModel + { + private static readonly RuntimeModel _instance = CreateModel(); + + public static IModel Instance + => _instance; + + private static RuntimeModel CreateModel() + { +#pragma warning disable CS0618 // Type or member is obsolete + var model = new RuntimeModel(); +#pragma warning restore CS0618 + model.AddAnnotation(CoreAnnotationNames.ProductVersion, ProductInfo.GetVersion()); + return model; + } + } +} From 3849e61d5478be8420456a552dc4f3511a7b2658 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 21:16:59 +0000 Subject: [PATCH 8/9] Rename CompiledModelProviderMismatchEventData to ProviderMismatchEventData Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- src/EFCore/Diagnostics/CoreLoggerExtensions.cs | 4 ++-- ...viderMismatchEventData.cs => ProviderMismatchEventData.cs} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/EFCore/Diagnostics/{CompiledModelProviderMismatchEventData.cs => ProviderMismatchEventData.cs} (93%) diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index 1965c3bcf82..b11f4d65297 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -253,7 +253,7 @@ public static void CompiledModelProviderMismatchWarning( if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled)) { - var eventData = new CompiledModelProviderMismatchEventData( + var eventData = new ProviderMismatchEventData( definition, CompiledModelProviderMismatch, compiledProviderName, @@ -266,7 +266,7 @@ public static void CompiledModelProviderMismatchWarning( private static string CompiledModelProviderMismatch(EventDefinitionBase definition, EventData payload) { var d = (EventDefinition)definition; - var p = (CompiledModelProviderMismatchEventData)payload; + var p = (ProviderMismatchEventData)payload; return d.GenerateMessage(p.CompiledProviderName, p.CurrentProviderName); } diff --git a/src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs b/src/EFCore/Diagnostics/ProviderMismatchEventData.cs similarity index 93% rename from src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs rename to src/EFCore/Diagnostics/ProviderMismatchEventData.cs index c602e7040a3..5dc456631b9 100644 --- a/src/EFCore/Diagnostics/CompiledModelProviderMismatchEventData.cs +++ b/src/EFCore/Diagnostics/ProviderMismatchEventData.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; /// /// See Logging, events, and diagnostics for more information and examples. /// -public class CompiledModelProviderMismatchEventData : EventData +public class ProviderMismatchEventData : EventData { /// /// Constructs the event payload. @@ -18,7 +18,7 @@ public class CompiledModelProviderMismatchEventData : EventData /// A delegate that generates a log message for this event. /// The provider name stored in the compiled model. /// The provider name currently configured. - public CompiledModelProviderMismatchEventData( + public ProviderMismatchEventData( EventDefinitionBase eventDefinition, Func messageGenerator, string compiledProviderName, From 7e1dd4cf61547ca37a2224e198cde52937025568 Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Wed, 4 Mar 2026 13:35:19 -0800 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/EFCore/Diagnostics/CoreEventId.cs | 2 +- .../Diagnostics/ProviderMismatchEventData.cs | 60 +++++++++---------- src/EFCore/Properties/CoreStrings.Designer.cs | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/EFCore/Diagnostics/CoreEventId.cs b/src/EFCore/Diagnostics/CoreEventId.cs index 717abcdb16c..c7f4b9a901c 100644 --- a/src/EFCore/Diagnostics/CoreEventId.cs +++ b/src/EFCore/Diagnostics/CoreEventId.cs @@ -500,7 +500,7 @@ private static EventId MakeInfraId(Id id) /// This event is in the category. /// /// - /// This event uses the payload when used with a . + /// This event uses the payload when used with a . /// /// public static readonly EventId CompiledModelProviderMismatchWarning = MakeInfraId(Id.CompiledModelProviderMismatchWarning); diff --git a/src/EFCore/Diagnostics/ProviderMismatchEventData.cs b/src/EFCore/Diagnostics/ProviderMismatchEventData.cs index 5dc456631b9..4501cbc536d 100644 --- a/src/EFCore/Diagnostics/ProviderMismatchEventData.cs +++ b/src/EFCore/Diagnostics/ProviderMismatchEventData.cs @@ -3,39 +3,39 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; -/// -/// A event payload class for compiled model provider mismatch warnings. -/// -/// -/// See Logging, events, and diagnostics for more information and examples. -/// -public class ProviderMismatchEventData : EventData -{ /// - /// Constructs the event payload. + /// A event payload class for provider mismatch warnings. /// - /// The event definition. - /// A delegate that generates a log message for this event. - /// The provider name stored in the compiled model. - /// The provider name currently configured. - public ProviderMismatchEventData( - EventDefinitionBase eventDefinition, - Func messageGenerator, - string compiledProviderName, - string currentProviderName) - : base(eventDefinition, messageGenerator) + /// + /// See Logging, events, and diagnostics for more information and examples. + /// + public class ProviderMismatchEventData : EventData { - CompiledProviderName = compiledProviderName; - CurrentProviderName = currentProviderName; - } + /// + /// Constructs the event payload. + /// + /// The event definition. + /// A delegate that generates a log message for this event. + /// The provider name stored with the model. + /// The provider name currently configured. + public ProviderMismatchEventData( + EventDefinitionBase eventDefinition, + Func messageGenerator, + string compiledProviderName, + string currentProviderName) + : base(eventDefinition, messageGenerator) + { + CompiledProviderName = compiledProviderName; + CurrentProviderName = currentProviderName; + } - /// - /// The provider name stored in the compiled model. - /// - public virtual string CompiledProviderName { get; } + /// + /// The provider name stored with the model. + /// + public virtual string CompiledProviderName { get; } - /// - /// The provider name currently configured. - /// - public virtual string CurrentProviderName { get; } + /// + /// The provider name currently configured. + /// + public virtual string CurrentProviderName { get; } } diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 814ad895a05..60ba4290e46 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -4723,7 +4723,7 @@ public static EventDefinition LogOldModelVersion(IDiagnosticsLog } /// - /// A compiled model was found but was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Update the compiled model to use the correct provider. + /// A compiled model was found but was built for the database provider '{compiledProviderName}'. The current context is using the database provider '{currentProviderName}'. The compiled model was ignored. Regenerate the compiled model to use the correct provider. /// public static EventDefinition LogCompiledModelProviderMismatch(IDiagnosticsLogger logger) {