-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Traverses a graph and provides a callback for each entry visited. See #1229 No async version yet, and no higher-level overloads.
- Loading branch information
1 parent
48b776f
commit 0feb4cf
Showing
9 changed files
with
457 additions
and
148 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
70 changes: 70 additions & 0 deletions
70
src/EntityFramework.Core/ChangeTracking/EntityEntryGraphIterator.cs
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,70 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using Microsoft.Data.Entity.Infrastructure; | ||
using Microsoft.Data.Entity.Metadata; | ||
using Microsoft.Data.Entity.Utilities; | ||
|
||
namespace Microsoft.Data.Entity.ChangeTracking | ||
{ | ||
public class EntityEntryGraphIterator | ||
{ | ||
private readonly DbContextService<DbContext> _context; | ||
|
||
public EntityEntryGraphIterator( | ||
[NotNull] DbContextService<DbContext> context) | ||
{ | ||
Check.NotNull(context, "context"); | ||
|
||
_context = context; | ||
} | ||
|
||
public virtual IEnumerable<EntityEntry> TraverseGraph([NotNull] object entity) | ||
{ | ||
Check.NotNull(entity, "entity"); | ||
|
||
var entry = _context.Service.Entry(entity); | ||
|
||
if (entry.State != EntityState.Unknown) | ||
{ | ||
yield break; | ||
} | ||
|
||
yield return entry; | ||
|
||
if (entry.State != EntityState.Unknown) | ||
{ | ||
var navigations = entry.StateEntry.EntityType.Navigations; | ||
|
||
foreach (var navigation in navigations) | ||
{ | ||
var navigationValue = entry.StateEntry[navigation]; | ||
|
||
if (navigationValue != null) | ||
{ | ||
if (navigation.IsCollection()) | ||
{ | ||
foreach (var relatedEntity in (IEnumerable)navigationValue) | ||
{ | ||
foreach (var relatedEntry in TraverseGraph(relatedEntity)) | ||
{ | ||
yield return relatedEntry; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
foreach (var relatedEntry in TraverseGraph(navigationValue)) | ||
{ | ||
yield return relatedEntry; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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.