diff --git a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs index 3c77010b2f7..10ed1eb53ba 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs @@ -61,6 +61,7 @@ protected RelationalOptionsExtension(RelationalOptionsExtension copyFrom) _useRelationalNulls = copyFrom._useRelationalNulls; _querySplittingBehavior = copyFrom._querySplittingBehavior; _migrationsAssembly = copyFrom._migrationsAssembly; + _migrationsAssemblyObject = copyFrom._migrationsAssemblyObject; _migrationsHistoryTableName = copyFrom._migrationsHistoryTableName; _migrationsHistoryTableSchema = copyFrom._migrationsHistoryTableSchema; _executionStrategyFactory = copyFrom._executionStrategyFactory; diff --git a/test/EFCore.Relational.Tests/Infrastructure/RelationalOptionsExtensionTest.cs b/test/EFCore.Relational.Tests/Infrastructure/RelationalOptionsExtensionTest.cs index 25ccfc38ded..bea88810af3 100644 --- a/test/EFCore.Relational.Tests/Infrastructure/RelationalOptionsExtensionTest.cs +++ b/test/EFCore.Relational.Tests/Infrastructure/RelationalOptionsExtensionTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Reflection; using Microsoft.EntityFrameworkCore.TestUtilities.FakeProvider; // ReSharper disable InconsistentNaming @@ -94,4 +95,25 @@ public void Throws_if_MinBatchSize_out_of_range() RelationalStrings.InvalidMinBatchSize(-1), Assert.Throws( () => new FakeRelationalOptionsExtension().WithMinBatchSize(-1)).Message); + + [ConditionalFact] + public void MigrationsAssemblyObject_is_preserved_after_cloning() + { + var optionsExtension = new FakeRelationalOptionsExtension(); + + // Get the current executing assembly + var assembly = Assembly.GetExecutingAssembly(); + + // Set the migrations assembly + optionsExtension = (FakeRelationalOptionsExtension)optionsExtension.WithMigrationsAssembly(assembly); + + // Verify the migrations assembly object is set + Assert.Same(assembly, optionsExtension.MigrationsAssemblyObject); + + // Clone the options by using another With method (which internally calls Clone()) + optionsExtension = (FakeRelationalOptionsExtension)optionsExtension.WithCommandTimeout(100); + + // Verify the migrations assembly object is still preserved after cloning + Assert.Same(assembly, optionsExtension.MigrationsAssemblyObject); + } }