From 44610a44acbc8cc7ead3be17c1c771f8bf8c8ec5 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Mon, 15 May 2017 16:09:56 -0700 Subject: [PATCH] Update database error page to react to EF logging changes. --- .../DataStoreErrorLogger.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore/DataStoreErrorLogger.cs b/src/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore/DataStoreErrorLogger.cs index e4ab315..6a8455f 100644 --- a/src/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore/DataStoreErrorLogger.cs +++ b/src/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore/DataStoreErrorLogger.cs @@ -3,9 +3,13 @@ using JetBrains.Annotations; using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Utilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; +using System.Linq; using System.Threading; namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore @@ -34,10 +38,14 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore public virtual void Log(LogLevel logLevel, EventId eventId, [CanBeNull] TState state, [CanBeNull] Exception exception, [CanBeNull] Func formatter) { - var errorState = state as DatabaseErrorLogState; - if (errorState != null && exception != null && LastError != null) + if (exception != null + && LastError != null + && (eventId.Id == CoreEventId.SaveChangesFailed.Id + || eventId.Id == CoreEventId.QueryIterationFailed.Id)) { - LastError.SetError(errorState.ContextType, exception); + LastError.SetError( + (Type)((IReadOnlyList>)state).Single(p => p.Key == "contextType").Value, + exception); } }