-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add events for entity state changes #10896
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.ChangeTracking | ||
{ | ||
/// <summary> | ||
/// Event arguments for events relating to tracked <see cref="EntityEntry" />s. | ||
/// </summary> | ||
public class EntityEntryEventArgs : EventArgs | ||
{ | ||
private readonly InternalEntityEntry _internalEntityEntry; | ||
private EntityEntry _entry; | ||
|
||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public EntityEntryEventArgs( | ||
[NotNull] InternalEntityEntry internalEntityEntry) | ||
{ | ||
_internalEntityEntry = internalEntityEntry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check not null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an internal constructor. |
||
} | ||
|
||
/// <summary> | ||
/// The <see cref="EntityEntry" /> for the entity. | ||
/// </summary> | ||
public virtual EntityEntry Entry => _entry ?? (_entry = new EntityEntry(_internalEntityEntry)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.ChangeTracking | ||
{ | ||
/// <summary> | ||
/// Event arguments for the <see cref="ChangeTracker.StateChanged" /> event. | ||
/// </summary> | ||
public class EntityStateEventArgs : EntityEntryEventArgs | ||
{ | ||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public EntityStateEventArgs( | ||
[NotNull] InternalEntityEntry internalEntityEntry, | ||
EntityState oldState, | ||
EntityState newState) | ||
: base(internalEntityEntry) | ||
{ | ||
OldState = oldState; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
NewState = newState; | ||
} | ||
|
||
/// <summary> | ||
/// The state that the entity is transitioning from. | ||
/// </summary> | ||
public virtual EntityState OldState { get; } | ||
|
||
/// <summary> | ||
/// The state that the entity is transitioning to. | ||
/// </summary> | ||
public virtual EntityState NewState { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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 JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.ChangeTracking | ||
{ | ||
/// <summary> | ||
/// Event arguments for the <see cref="ChangeTracker.Tracked" /> event. | ||
/// </summary> | ||
public class EntityTrackedEventArgs : EntityEntryEventArgs | ||
{ | ||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public EntityTrackedEventArgs( | ||
[NotNull] InternalEntityEntry internalEntityEntry, | ||
bool fromQuery) | ||
: base(internalEntityEntry) | ||
{ | ||
FromQuery = fromQuery; | ||
} | ||
|
||
/// <summary> | ||
/// <c>True</c> if the entity is being tracked as part of a database query; <c>false</c> otherwise. | ||
/// </summary> | ||
public virtual bool FromQuery { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide DbContext here, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its available on the EntityEntry