Skip to content

Commit fec5f42

Browse files
committed
call add using methodinfo
1 parent 6dbb35b commit fec5f42

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

JsonApiDotNetCore/Data/ResourceRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ private object GetEntityById(Type modelType, string id, string includedRelations
6767

6868
public void Add(object entity)
6969
{
70-
((DbSet<object>)GetDbSetFromContext(_context.Route.BaseRouteDefinition.ContextPropertyName)).Add(entity);
70+
var dbSetAddMethod = typeof(DbSet<>).GetMethod("Add");
71+
var dbSet = GetDbSetFromContext(_context.Route.BaseRouteDefinition.ContextPropertyName);
72+
dbSetAddMethod.Invoke(dbSet, new [] { entity });
7173
}
7274

7375
public int SaveChanges()

0 commit comments

Comments
 (0)