-
-
Notifications
You must be signed in to change notification settings - Fork 158
DefaultEntityRepository cleanup #518
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5f3e04b
refactor: AttachHasOnePointers
maurei e8d1096
refactor: AssignHasMany pointers
maurei 1420d6d
refactor assign relationships and applied to updateasync method
maurei 24dd97c
refactor: tests passing again
maurei 0304725
test: add implicit removal test
maurei f60587f
test: all passing
maurei 4cd9465
chore: addedd notes wrt implicit remove
maurei d1f39e6
comments: added comment to assign method
maurei bcbf8c3
Merge branch 'master' into fix/reattachment
maurei 7df5233
fix: support for entity resource split
maurei 0296eb4
fix: minor refactor, comments
maurei f0d5924
fix: foreignkey set null bug
maurei 9f7550c
feat: decoupled repository from JsonApiContext with respect to updati…
maurei 7aea60c
feat: decoupled IJsonApiContext from repository wrt updating resources
maurei 652d65f
fix: resource separation issue|
maurei 9838627
chore: cherry picked inverse relationships from hooks branch
maurei fbe69fc
fix: tests
maurei 35a2f54
feat: implicit remove support
maurei 6e6f7fa
fix: test
maurei c1d472d
fix: bugs with inverse relationship loading
maurei f45972f
tests: implicit remove through create tests
maurei d8b4217
feat: mark obsolete UpdateAsync(TId id, TEntity entity) method, add n…
maurei 30765c3
fix: #520
maurei 9139852
fix: separation tests
maurei 457e93d
chore: comments
maurei 65f8a3a
Update DefaultEntityRepository.cs
maurei 3ddb6a2
Update DefaultEntityRepository.cs
maurei 2437077
Update TypeExtensions.cs
maurei 415306e
Update DefaultEntityRepository.cs
maurei 52a452d
Update JsonApiReader.cs
maurei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
using JsonApiDotNetCore.Models; | ||
|
||
namespace JsonApiDotNetCoreExample.Models | ||
{ | ||
public class Passport : Identifiable | ||
{ | ||
public virtual int? SocialSecurityNumber { get; set; } | ||
[HasOne("person")] | ||
public virtual Person Person { get; set; } | ||
} | ||
} |
This file contains hidden or 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
436 changes: 271 additions & 165 deletions
436
src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,71 @@ | ||
using System; | ||
using JsonApiDotNetCore.Data; | ||
using JsonApiDotNetCore.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace JsonApiDotNetCore.Internal | ||
{ | ||
/// <summary> | ||
/// Responsible for populating the RelationshipAttribute InverseNavigation property. | ||
/// | ||
/// This service is instantiated in the configure phase of the application. | ||
/// | ||
/// When using a data access layer different from EF Core, and when using ResourceHooks | ||
/// that depend on the inverse navigation property (BeforeImplicitUpdateRelationship), | ||
/// you will need to override this service, or pass along the inverseNavigationProperty in | ||
/// the RelationshipAttribute. | ||
/// </summary> | ||
public interface IInverseRelationships | ||
{ | ||
/// <summary> | ||
/// This method is called upon startup by JsonApiDotNetCore. It should | ||
/// deal with resolving the inverse relationships. | ||
/// </summary> | ||
void Resolve(); | ||
maurei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// <inheritdoc /> | ||
public class InverseRelationships : IInverseRelationships | ||
{ | ||
private readonly ResourceGraph _graph; | ||
private readonly IDbContextResolver _resolver; | ||
|
||
public InverseRelationships(IResourceGraph graph, IDbContextResolver resolver = null) | ||
{ | ||
_graph = (ResourceGraph)graph; | ||
_resolver = resolver; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Resolve() | ||
maurei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (EntityFrameworkCoreIsEnabled()) | ||
{ | ||
DbContext context = _resolver.GetContext(); | ||
|
||
foreach (ContextEntity ce in _graph.Entities) | ||
{ | ||
IEntityType meta = context.Model.FindEntityType(ce.EntityType); | ||
if (meta == null) continue; | ||
foreach (var attr in ce.Relationships) | ||
{ | ||
if (attr is HasManyThroughAttribute) continue; | ||
INavigation inverseNavigation = meta.FindNavigation(attr.InternalRelationshipName)?.FindInverse(); | ||
attr.InverseNavigation = inverseNavigation?.Name; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// If EF Core is not being used, we're expecting the resolver to not be registered. | ||
/// </summary> | ||
/// <returns><c>true</c>, if entity framework core was enabled, <c>false</c> otherwise.</returns> | ||
/// <param name="resolver">Resolver.</param> | ||
private bool EntityFrameworkCoreIsEnabled() | ||
{ | ||
return _resolver != null; | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.