-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #15910 I realized that the interceptor, while powerful, is hard to attach to without changing the context configuration. Therefore, this PR adds simple .NET events that can easily be attached to from outside the code that defines the context. Also, fix to call the SaveChanges failed interceptor when the failure is an optimistic concurrency exception.
- Loading branch information
1 parent
f7fddae
commit 1c42f7b
Showing
9 changed files
with
356 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Base event arguments for the <see cref="M:DbContext.SaveChanges" /> and <see cref="M:DbContext.SaveChangesAsync" /> events. | ||
/// </summary> | ||
public abstract class SaveChangesEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// Creates a base event arguments instance for <see cref="M:DbContext.SaveChanges" /> | ||
/// or <see cref="M:DbContext.SaveChangesAsync" /> events. | ||
/// </summary> | ||
/// <param name="acceptAllChangesOnSuccess"> The value passed to SaveChanges. </param> | ||
protected SaveChangesEventArgs(bool acceptAllChangesOnSuccess) | ||
{ | ||
AcceptAllChangesOnSuccess = acceptAllChangesOnSuccess; | ||
} | ||
|
||
/// <summary> | ||
/// The value passed to <see cref="M:DbContext.SaveChanges" /> or <see cref="M:DbContext.SaveChangesAsync" />. | ||
/// </summary> | ||
public virtual bool AcceptAllChangesOnSuccess { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Event arguments for the <see cref="DbContext.SaveChangesFailed" /> event. | ||
/// </summary> | ||
public class SaveChangesFailedEventArgs : SaveChangesEventArgs | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="SaveChangesFailedEventArgs"/> instance with the exception that was thrown. | ||
/// </summary> | ||
/// <param name="acceptAllChangesOnSuccess"> The value passed to SaveChanges. </param> | ||
/// <param name="exception"> The exception thrown. </param> | ||
public SaveChangesFailedEventArgs(bool acceptAllChangesOnSuccess, [NotNull] Exception exception) | ||
: base(acceptAllChangesOnSuccess) | ||
{ | ||
Exception = exception; | ||
} | ||
|
||
/// <summary> | ||
/// The exception thrown during<see cref="M:DbContext.SaveChanges"/> or <see cref="M:DbContext.SaveChangesAsync"/>. | ||
/// </summary> | ||
public virtual Exception Exception { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Event arguments for the <see cref="DbContext.SavedChanges" /> event. | ||
/// </summary> | ||
public class SavedChangesEventArgs : SaveChangesEventArgs | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="SavedChangesEventArgs" /> instance with the given number of entities saved. | ||
/// </summary> | ||
/// <param name="acceptAllChangesOnSuccess"> The value passed to SaveChanges. </param> | ||
/// <param name="entitiesSavedCount"> The number of entities saved. </param> | ||
public SavedChangesEventArgs(bool acceptAllChangesOnSuccess, int entitiesSavedCount) | ||
: base(acceptAllChangesOnSuccess) | ||
{ | ||
EntitiesSavedCount = entitiesSavedCount; | ||
} | ||
|
||
/// <summary> | ||
/// The number of entities saved. | ||
/// </summary> | ||
public virtual int EntitiesSavedCount { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Event arguments for the <see cref="DbContext.SavingChanges" /> event. | ||
/// </summary> | ||
public class SavingChangesEventArgs : SaveChangesEventArgs | ||
{ | ||
/// <summary> | ||
/// Creates event arguments for the <see cref="M:DbContext.SavingChanges" /> event. | ||
/// </summary> | ||
/// <param name="acceptAllChangesOnSuccess"> The value passed to SaveChanges. </param> | ||
public SavingChangesEventArgs(bool acceptAllChangesOnSuccess) | ||
: base(acceptAllChangesOnSuccess) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.