@@ -8,31 +8,23 @@ namespace JsonApiDotNetCore.Internal
8
8
public class ContextGraph : IContextGraph
9
9
{
10
10
public List < ContextEntity > Entities { get ; set ; }
11
- public bool UsesDbContext { get ; set ; }
11
+ public bool UsesDbContext { get ; set ; }
12
12
13
13
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 ) ) ;
19
15
20
16
public ContextEntity GetContextEntity ( Type entityType )
21
- {
22
- return Entities
23
- . FirstOrDefault ( e =>
24
- e . EntityType == entityType ) ;
25
- }
17
+ => Entities . SingleOrDefault ( e => e . EntityType == entityType ) ;
26
18
27
19
public object GetRelationship < TParent > ( TParent entity , string relationshipName )
28
20
{
29
21
var parentEntityType = entity . GetType ( ) ;
30
22
31
23
var navigationProperty = parentEntityType
32
24
. GetProperties ( )
33
- . FirstOrDefault ( p => p . Name . ToLower ( ) == relationshipName . ToLower ( ) ) ;
25
+ . SingleOrDefault ( p => string . Equals ( p . Name , relationshipName , StringComparison . OrdinalIgnoreCase ) ) ;
34
26
35
- if ( navigationProperty == null )
27
+ if ( navigationProperty == null )
36
28
throw new JsonApiException ( 400 , $ "{ parentEntityType } does not contain a relationship named { relationshipName } ") ;
37
29
38
30
return navigationProperty . GetValue ( entity ) ;
@@ -42,11 +34,9 @@ public string GetRelationshipName<TParent>(string relationshipName)
42
34
{
43
35
var entityType = typeof ( TParent ) ;
44
36
return Entities
45
- . FirstOrDefault ( e =>
46
- e . EntityType == entityType )
37
+ . SingleOrDefault ( e => e . EntityType == entityType )
47
38
. Relationships
48
- . FirstOrDefault ( r =>
49
- r . PublicRelationshipName . ToLower ( ) == relationshipName . ToLower ( ) )
39
+ . SingleOrDefault ( r => string . Equals ( r . PublicRelationshipName , relationshipName , StringComparison . OrdinalIgnoreCase ) )
50
40
? . InternalRelationshipName ;
51
41
}
52
42
}
0 commit comments