@@ -8,31 +8,23 @@ namespace JsonApiDotNetCore.Internal
88 public class ContextGraph : IContextGraph
99 {
1010 public List < ContextEntity > Entities { get ; set ; }
11- public bool UsesDbContext { get ; set ; }
11+ public bool UsesDbContext { get ; set ; }
1212
1313 public ContextEntity GetContextEntity ( string entityName )
14- {
15- return Entities
16- . FirstOrDefault ( e =>
17- e . EntityName . ToLower ( ) == entityName . ToLower ( ) ) ;
18- }
14+ => Entities . SingleOrDefault ( e => string . Equals ( e . EntityName , entityName , StringComparison . OrdinalIgnoreCase ) ) ;
1915
2016 public ContextEntity GetContextEntity ( Type entityType )
21- {
22- return Entities
23- . FirstOrDefault ( e =>
24- e . EntityType == entityType ) ;
25- }
17+ => Entities . SingleOrDefault ( e => e . EntityType == entityType ) ;
2618
2719 public object GetRelationship < TParent > ( TParent entity , string relationshipName )
2820 {
2921 var parentEntityType = entity . GetType ( ) ;
3022
3123 var navigationProperty = parentEntityType
3224 . GetProperties ( )
33- . FirstOrDefault ( p => p . Name . ToLower ( ) == relationshipName . ToLower ( ) ) ;
25+ . SingleOrDefault ( p => string . Equals ( p . Name , relationshipName , StringComparison . OrdinalIgnoreCase ) ) ;
3426
35- if ( navigationProperty == null )
27+ if ( navigationProperty == null )
3628 throw new JsonApiException ( 400 , $ "{ parentEntityType } does not contain a relationship named { relationshipName } ") ;
3729
3830 return navigationProperty . GetValue ( entity ) ;
@@ -42,11 +34,9 @@ public string GetRelationshipName<TParent>(string relationshipName)
4234 {
4335 var entityType = typeof ( TParent ) ;
4436 return Entities
45- . FirstOrDefault ( e =>
46- e . EntityType == entityType )
37+ . SingleOrDefault ( e => e . EntityType == entityType )
4738 . Relationships
48- . FirstOrDefault ( r =>
49- r . PublicRelationshipName . ToLower ( ) == relationshipName . ToLower ( ) )
39+ . SingleOrDefault ( r => string . Equals ( r . PublicRelationshipName , relationshipName , StringComparison . OrdinalIgnoreCase ) )
5040 ? . InternalRelationshipName ;
5141 }
5242 }
0 commit comments