So we now have a Trainee class, and an IDataProvider interface. An interface is not much use without an implementation, so the next step is to create an SqlDataProvider class which impements IDataProvider.

I won't bore you with the details, but the SqlDataProvider class lives in its own assembly, but we kept it in the Qaf.TrainAlloc.DataProviders namespace. It uses SqlConnection, SqlCommand and SqlDataReader objects to talk to SQL Server. GetAllTrainees() builds up a List<TraineeDataContract> collection and returns it to the caller. SaveTrainee() checks if there is already a trainee with the supplied ID in the table, and creates or updates accordingly.

We now had the code written, and we knew it compiled, but we had no idea whether it was going to work. Ordinarily at this stage we'd have knocked up a console application to call the methods and check if they error, but we knew there was a better way than that. Enter NUnit - in the next post!