I need to store a calibration into two tables simultaneously, with one table describing the instance of the calibration (operator, date, station) and the other storing the raw data in multiple rows (9 or 10 pairs of wavelength and responsivity for a single calibration). The schema for this is below:
An example calibration:
The SpectrometerCalibration.ID = SpectrometerCalibrationID for all calibration points. What I've tried (acutally using LINQ to SQL in vb.net so treat as pseudo-code)
INSERT INTO SpectrometerCalibration (StationID, OperatorID, Date) VALUES (7, 2, '2013/10/21 11:00:00.000 AM')
SELECT TOP 1 ID FROM SpectrometerCalibration ORDER BY ID DESC
-- Insert once for each wavelength / responsivity pair
INSERT INTO SpectrometerCalibrationValues (SpectrometerCalibrationID, Wavelength, Responsivity) VALUES (<from previous query>, <wl>, <val>)
This solution has an issue with timing. If two stations are calibrating simultaneously, the incorrect ID could be returned. I believe this is poor design. Trying to avoid this method.
I have seen many more complicated questions on SO, but none seem to solve my problem. I assume there is a standard way to do this correctly. No, I can't change this schema. I am using LINQ to SQL in vb.net. Is a better way to do it?