public async Task CreateVehicle(CreateVehicleModel vehicle) { var vehicleType = await _typeRepo .GetVehicleTypesByName(vehicle.VehicleType) .SingleOrDefaultAsync(); if (vehicleType == null) { vehicleType = new ExampleVehicleType { Name = vehicle.VehicleType }; await _typeRepo.Add(vehicleType); } var entity = Mapper.Map <ExampleVehicle>(vehicle); entity.VehicleType = vehicleType; await _vehicleRepo.Add(entity); }