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
100
100
var entityType = dbSetType . GetGenericArguments ( ) [ 0 ] ;
101
101
entities . Add ( new ContextEntity
102
102
{
103
- EntityName = property . Name . Dasherize ( ) ,
103
+ EntityName = GetResourceName ( property ) ,
104
104
EntityType = entityType ,
105
105
Attributes = GetAttributes ( entityType ) ,
106
106
Relationships = GetRelationships ( entityType )
@@ -110,5 +110,14 @@ public void AddDbContext<T>() where T : DbContext
110
110
111
111
Entities = entities ;
112
112
}
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
+ }
113
122
}
114
123
}
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