From fae4e6ec717735338a9b64ae2540caf65892ab73 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Tue, 26 Jul 2022 11:54:28 +0100 Subject: [PATCH] Move setting flag to Execute method. --- src/EFCore.Design/Design/OperationExecutor.cs | 6 +++++- test/EFCore.Design.Tests/Design/OperationExecutorTest.cs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs index 73dae4cbe28..e9a7295a62f 100644 --- a/src/EFCore.Design/Design/OperationExecutor.cs +++ b/src/EFCore.Design/Design/OperationExecutor.cs @@ -697,7 +697,6 @@ public abstract class OperationBase : MarshalByRefObject /// The . protected OperationBase(IOperationResultHandler resultHandler) { - EF.IsDesignTime = true; _resultHandler = resultHandler; } @@ -707,6 +706,7 @@ protected OperationBase(IOperationResultHandler resultHandler) /// The action to execute. protected virtual void Execute(Action action) { + EF.IsDesignTime = true; try { action(); @@ -715,6 +715,10 @@ protected virtual void Execute(Action action) { _resultHandler.OnError(ex.GetType().FullName!, ex.Message, ex.ToString()); } + finally + { + EF.IsDesignTime = false; + } } /// diff --git a/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs b/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs index ce57bf03a06..072b5f8cf5b 100644 --- a/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs +++ b/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs @@ -23,12 +23,15 @@ public void Operations_have_design_time_flag_set() var handler = new OperationResultHandler(); var result = "Twilight Sparkle"; + Assert.False(EF.IsDesignTime); + new MockOperation(handler, () => { Assert.True(EF.IsDesignTime); return result; }); + Assert.False(EF.IsDesignTime); Assert.Equal(result, handler.Result); }