public async Task <object> UpdateAsync <T>(string source, string id, dynamic item) where T : class, IEntity { var repo = new EntityFrameworkRepository <T>(dbContext); var existing = await repo.FindAsync(e => e.Source == source && e.Id == id); if (existing == null || existing.Count() == 0) { throw new KeyNotFoundException($"Entity {typeof(T)} with source {source} and id {id} not found"); } await repo.DeleteAsync(existing.First()); var inItem = JsonConvert.DeserializeObject <T>(JsonConvert.SerializeObject(item)); await repo.CreateAsync(inItem); return(inItem); }