Repository.addorupdate(entity, entity.id); Repository.savechanges(); Var id = entity.id;
Это будет работать.