private static void SeedPrescriptions(HospitalContext context, int prescriptionSeeds) { int[] patientIds = context.Patients.Select(p => p.PatientId).ToArray(); int[] medicamentIds = context.Medicaments.Select(m => m.MedicamentId).ToArray(); if (patientIds.Length > 0 && medicamentIds.Length > 0) { var prescriptions = context.PatientsMedicaments.ToList(); for (int prs = 1; prs <= prescriptionSeeds; prs++) { int patientId = patientIds[rng.Next(patientIds.Length)]; int medicamentId = medicamentIds[rng.Next(medicamentIds.Length)]; PatientMedicament prescription = PrescriptionGenerator .GeneratePrescription(patientId, medicamentId); if (!prescriptions.Any(pr => pr.CompareTo(prescription) == 0)) { prescriptions.Add(prescription); } } context.PatientsMedicaments.AddRange(prescriptions); context.SaveChanges(); } }
private static void SeedPrescriptions(HospitalContext context) { PrescriptionGenerator.InitialPrescriptionSeed(context); }