File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ public void AddDbContext<T>() where T : DbContext
100100 var entityType = dbSetType . GetGenericArguments ( ) [ 0 ] ;
101101 entities . Add ( new ContextEntity
102102 {
103- EntityName = property . Name . Dasherize ( ) ,
103+ EntityName = GetResourceName ( property ) ,
104104 EntityType = entityType ,
105105 Attributes = GetAttributes ( entityType ) ,
106106 Relationships = GetRelationships ( entityType )
@@ -110,5 +110,14 @@ public void AddDbContext<T>() where T : DbContext
110110
111111 Entities = entities ;
112112 }
113+
114+ private string GetResourceName ( PropertyInfo property )
115+ {
116+ var resourceAttribute = property . GetCustomAttribute ( typeof ( ResourceAttribute ) ) ;
117+ if ( resourceAttribute == null )
118+ return property . Name . Dasherize ( ) ;
119+
120+ return ( ( ResourceAttribute ) resourceAttribute ) . ResourceName ;
121+ }
113122 }
114123}
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace JsonApiDotNetCore . Models
4+ {
5+ public class ResourceAttribute : Attribute
6+ {
7+ public ResourceAttribute ( string resourceName )
8+ {
9+ ResourceName = resourceName ;
10+ }
11+
12+ public string ResourceName { get ; set ; }
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments